Any practical example of LockSupport & AbstractQueuedSynchronizer use?

前端 未结 5 1243
情深已故
情深已故 2020-12-28 20:24

Guys, can anyone give a simple practical example of LockSupport & AbstractQueuedSynchronizer use? Example given in javadocs is quite strained.<

5条回答
  •  暖寄归人
    2020-12-28 20:50

    AFAIK, AbstractQueuedSynchronizer is used to manage state transitions. The JDK uses it to extend Sync, an internal class for java.util.concurrent.FutureTask. The Sync class manages the states (READY, RUNNING, RAN, and CANCELLED) of FutureTask and the transitions between them.

    This allows, as you may know, FutureTask to block on FutureTask.get() until the RAN state is reached, for example.

提交回复
热议问题