- Loading...
...
The following is an example that creates a virtual thread that puts an element into a queue when it has completed a task, the . The main thread blocks on the queue, waiting for the element.
| Code Block | ||
|---|---|---|
| ||
var queue = new SynchronousQueue<String>();
Thread.startVirtualThread(() -> {
try {
Thread.sleep(Duration.ofSeconds(2));
queue.put("done");
} catch (InterruptedException e) { }
});
String msg = queue.take(); |
...