Is there any example/scenario to illustrate [LockSupport
] is useful?
Look through the source code of the Java concurrency classes to find where the class is used:
These are examples of the kind of scenario where LockSupport
is useful.
They probably also illustrate the comment in the javadoc that you quoted. These primitives are low-level, and difficult to use directly.
To get you started, LockSupport
is used in the following classes in the standard class libraries (Java 8):
- java.util.concurrent.Exchanger
- java.util.concurrent.CompletableFuture
- java.util.concurrent.SynchronousQueue
- java.util.concurrent.ConcurrentHashMap
- java.util.concurrent.locks.StampedLock
- java.util.concurrent.locks.AbstractQueuedSynchronizer
- java.util.concurrent.locks.AbstractQueuedLongSynchronizer
- java.util.concurrent.LinkedTransferQueue
- java.util.concurrent.FutureTask
- java.util.concurrent.ForkJoinPool
- java.util.concurrent.Phaser