CompletableFuture.join(): retrieving the result
`join()` retrieves a `CompletableFuture` result, waiting for completion if necessary. It declares no checked exceptions, but it can still throw an unchecked exception.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
`join()` retrieves a `CompletableFuture` result, waiting for completion if necessary. It declares no checked exceptions, but it can still throw an unchecked exception.
Pass a custom `Executor` to choose how the task runs. A direct executor such as `Runnable::run` runs the task immediately on the calling thread instead of using the common pool.
Use `thenApply` to transform a stage’s result after it completes normally. It returns a new stage and does not guarantee that the function runs on a separate thread.
`thenCombine` creates a new `CompletableFuture` whose value is computed only after both input stages complete normally, for example to add the counts from two independent operations.
CompletionException is an unchecked exception signaling a failure while completing a task or result. With CompletableFuture, it carries the underlying failure to code retrieving the result through join().
Use `computeIfAbsent` to initialize a `LongAdder` atomically for a missing key, then use `forEach` to read counts without depending on traversal order.
Use `get` to read, `put` to write unconditionally, and `merge` to update one key atomically, for example when threads share a counter.
Wait for a state change in a loop, carry forward the remaining nanosecond budget, and choose whether to wake one waiter or all of them.
Invoke a specific constructor in Java SE 21 and distinguish lookup or invocation failures from exceptions thrown by the constructor itself.
Select the single `@Inject` constructor or fall back to a no-argument constructor when none is marked. Check parameter types and access before invoking it.
Use a one-shot counter to open a start gate or wait for a fixed number of signals. Learn both await overloads, how interruption works, and when writes become visible across threads.
AEADBadTagException means that a Cipher operating in an AEAD mode, such as GCM or CCM, could not verify the authentication tag. Reject the data rather than treating it as successfully decrypted.
Cipher provides encryption and decryption through Java cryptographic providers. AES-GCM protects data confidentiality and detects modifications; correct use requires a unique IV for each key and verification of the authentication tag.
GCMParameterSpec supplies Cipher with an initialization vector and authentication tag length. The object itself neither encrypts data nor ensures IV uniqueness.
The javax.crypto.Mac class computes a message authentication code using a secret key. Learn how to select HmacSHA256, initialize it with a key, and finish the computation with doFinal.
SecretKeySpec wraps existing key bytes and an algorithm name. It copies the data but does not check its cryptographic validity.
Synchronize a fixed number of threads between phases, run one shared action before they proceed, and distinguish timed from untimed waits.
DataInputStream reads primitive values and strings from a binary stream. You must know the field order and encoding; it does not parse numbers written as text.
DataOutputStream writes primitive values and strings to a binary stream in a defined format. Learn the byte widths, byte order, and limitations of writeUTF.
Read fields in the same order you wrote them. See how Java SE 21 lays out numeric values and why the `writeUTF` limit counts encoded bytes, not characters.
Choose a pattern and locale to control the text, and a resolver style to control date validation. Learn why `MM` differs from `mm` and when to use `uuuu` instead of `yyyy`.
Build a formatter for `yyyy-MM-dd HH:mm z` with an explicit `Locale.ENGLISH`, and learn where the time zone in the output comes from.
Learn to insert, inspect, and remove elements at either end of a `Deque`, and know when to expect `false`, `null`, or an exception.
Compare two primitive `double` values by reading the sign of the result. Learn how the method distinguishes signed zeros and places `NaN` last in ascending order.