I am using multi-threading in java for my program.
I have run thread successfully but when I am using Thread.wait()
, it is throwing java.lang.IllegalMonit
I received a IllegalMonitorStateException
while trying to wake up a thread in / from a different class
/ thread. In java 8
you can use the lock features of the new Concurrency API instead of synchronized
functions.
I was already storing objects for asynchronous
websocket transactions in a WeakHashMap
. The solution in my case was to also store a lock object in a ConcurrentHashMap for synchronous
replies. Note the condition.await
(not .wait
).
To handle the multi threading I used a Executors.newCachedThreadPool()
to create a thread pool.