开发者

Using getState() method on Threads - Java

开发者 https://www.devze.com 2023-04-12 05:32 出处:网络
Lets say we have two Threads A, B and one Mutex (Share开发者_如何学God resource) M. I start the A thread (a.start()), and it will call a synchronized method in M and it causes A to wait(). How can t

Lets say we have two Threads A, B and one Mutex (Share开发者_如何学God resource) M.

I start the A thread (a.start()), and it will call a synchronized method in M and it causes A to wait(). How can the thread B (b) follow A after A enters wait() ?

thanks

EDIT:

Is there a method "similar" to join() in which the thread b will join the thread started a when it is in WAITING state? (As I found , join() will happen when the thread finishes, but i don't want that to happen


A object in thread "t" can call wait if in a synchronized block, and the jvm will manage the execution of synchronous blocks that are running... --- It's actually quite simple, objects that are waiting will grab the lock of that threads execution when an opposing object yields, and start working.... So, in short, your object B will start running if it:

1) is in the same thread as A

2) is "wait()"ing when A stops running

3) is executing in a synchronous block

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号