...
| Code Block |
|---|
|
Instant deadline = Instant.now().plusSeconds(30);
try (ExecutorService executor = Executors.newUnboundedExecutor(factory).withDeadline(deadline)) {
:
} |
Appendix: Differences between regular Threads and virtual Threads
Thread API
- VirtualThread always report their priority as NORM_PRIORITY. The priority is not inherited and cannot be changed with the setPriority method.
- Virtual threads are daemon threads. Their daemon status cannot be changed with the setDaemon method.
- Virtual threads cannot be suspend, resumed or stopped with the Thread suspend, resume and stop APIs.
- Virtual threads have no permissions when running with a security manager.
- Virtual threads are not active threads in their thread group. The getThreadGroup method returns a ThreadGroup that cannot be destroyed and its enumerate methods do not enumerate the virtual threads in the group.
...