开发者

Using getState() method on Threads - Java

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜