I have used basic object.wait()
, object.notify() , object.notifyAll()
in multi-threaded programming.
I know we have the package java.util.concurrent
and it has java.util.concurrent.locks
package. Specifically in java.util.concurrent.locks
we have : Condition
, Lock
and LockSupport
(among others).
I read online about this package, and understood basics of Lock
and Condition
. However, I didn't understand LockSupport
. I did search to understand LockSupport
, however didn't find anything relevant which can help me understand what it is used for. I have seen that in LockSupport
we have methods like park()
, unPark()
etc. However, I didn't get what is the purpose of LockSupport
, it seems to be doing more or less same like Lock
?
Can anyone please help me understand why we have LockSupport
and what it does that Lock
don't do.
It's a helper class with very low level concurrency mechanisms that are used by the other classes. Unless you want to write your own higher level concurrency structures, you probably won't use it.
There are other helper classes like java.util.concurrent.locks.AbstractQueuedSynchronizer
, which provide other mechanisms (e.g. wait queues in case of AQS
) to the classes that you are more likely to use, like ReentrantLock
and so on.