posted 24 years ago
Thanks for all your kind reply.
So now I see that the static method sleep() of Thread won't relinquish the lock of the object if it happened to be called inside synchronized method. And sleep() is definitely different from wait() since the latter must be called inside synchronized block.
But nobody answered my other question: what happened if interrupt() is called on this thread? I assume the thread will immediately relinquish the lock it holds if this method is called inside a synchronized block. But if the thread is interrupted while it is still in waiting state, the InterruptedException won't be thrown until the thread re-obtain the lock, and entering running state at the mercy of Thread scheduler. Right?
Question about another static method of Thread, yield(): java API says: Causes the currently executing thread object to temporarily pause and allow other threads to excute. So what kinds of threads will get the chance to excute? Those threads who have higher or equal priority as the current Thread? It is said that the when a Thread gets to run is platform-dependent because some platforms may use priority-preemptive mechanism,i.e, threads of lower thread never get chance to run before all other threads with higher priority die, and some platform have time-slice mechanism, in this case lower priority and higher priority thread alternatively get chance to run. Therefore, does this mean on different platform, yield() will enable different thread to execute, including threads whose priority is lower than current ones?
Judy