Skip to main content

Command Palette

Search for a command to run...

Java 21

Published
1 min readView as Markdown

SequencedCollection/Set/Map (Java 21)

  • unify collections with a defined order.

  • They add first, last, reversed, and add/remove at ends methods.

  • Implemented by List, LinkedHashSet, LinkedHashMap, SortedMap, etc.

  • Solve the problem of inconsistent handling of ordered collections.

Virtual Threads in Java

✅ What are they?

  • Lightweight threads introduced by Project Loom.

  • They are not OS threads, but run on top of platform (carrier) threads.

  • Created and managed by the JVM, stored in the Java heap (unlike platform threads which are tied to the OS).


🔑 How they work

  • A virtual thread is mounted on a carrier thread (platform thread) when executing.

  • If the virtual thread blocks (e.g., waiting on I/O), it is unmounted from the carrier → freeing the carrier thread.

  • When ready, it can be remounted on the same or another carrier thread.

  • The JVM keeps a snapshot of the virtual thread’s stack frames in the heap during unmount.


⚙️ Monitoring

  • Virtual threads can be monitored using ThreadMXBean from java.lang.management.

  • They behave like normal threads for debugging/monitoring purposes, but with much lower resource cost.