0

Threads can wait until other threads release lock which accessing synchronized block. I would like to know how long a thread can wait while other thread accessing synchronized block? and when will it come to know that the other thread released lock?

4

1 回答 1

1

如果变量lock已在一个线程中同步,则所有其他尝试用于lock同步的线程将被阻塞,直到lock不再同步。

//all other threads waiting on thread 1...
synchronized(lock)
{
    //thread 1 storing digits of pi into linked list... or whatevs.
}

正如其他人所说,线程将无限期地等待变量变得空闲以进行同步。

于 2013-08-28T17:30:48.620 回答