Skip to main content

Practice ยท 2 of 2

Timeouts are survival

CHALLENGE
Difficulty: advanced+25 XP

1. static int readWithBudget(java.io.Reader r, int budgetChars) โ€” read up to budgetChars characters into a String, then return the string LENGTH (simulates a bounded read; use the reader's real read(char[]) loop). 2. static long elapsedOf(java.util.function.Supplier<?> work) โ€” nanoTime around work.get(), return elapsed nanos (the shape of every timeout guard). 3. static String statusFor(long elapsedNanos, long deadlineNanos) โ€” return "ok" if elapsed <= deadline else "timeout".

Back to lesson: Practice: Socket drills