thread synchronization

hello,can three or more threads be synchronized on the same object? I want thread1 to execute first, then thread3 and then thread2 for some time... and for some duration of time i want them to execute in different order....can this be done?thanks in advance..
[294 byte] By [java_prog_newa] at [2007-10-3 3:41:25]
# 1
Why? Why not just code the method calls or execution blocks in the order you want them?
ejpa at 2007-7-14 21:37:14 > top of Java-index,Core,Core APIs...
# 2

It sounds like you want to control the scheduling of the threads and that is generally a bad idea. As ejb indicates why bother with the threads - just execute the code in the order you want it.

If you do want to experiment with this then you will have to write your own coordination logic using wait/notify or j.u.c Conditions/Locks, where each thread pools to see when it should stop executing and then waits until it is its turn again. Generally this works best with some kind of supervisor that oversees each thread and can implement the scheduling strategy. But this has to be cooperative, you cannot force thread 1, for example, to stop executing after X ms until thread 2 has done something. It isn't a trivial exercise even cooperatively.

davidholmesa at 2007-7-14 21:37:14 > top of Java-index,Core,Core APIs...
# 3
And note that monitor queues and wait-sets are not processed FIFO so you can't just let thread 1 grab a lock and run, let thread 3 try to acquire next and block, then thread 2, and expect thread 3 to get the lock when thread 1 releases it - it need not happen that way.
davidholmesa at 2007-7-14 21:37:14 > top of Java-index,Core,Core APIs...