Porque o monitor não dá deadlock  XML
Índice dos Fóruns » Java Avançado
Autor Mensagem
soaresinfo
JavaEvangelist
[Avatar]

Membro desde: 27/07/2003 15:40:13
Mensagens: 373
Localização: Uberlândia/MG
Offline

Eu tenho o seguinte codigo:


e este em outro metodo:


se eu chamei o wait no bloco synchronized, porque eu consigo chamar o seu notify se a thread parou de executar ainda dentro do synchronized??

Anuncie aqui!
kuchma
Moderador
[Avatar]

Membro desde: 17/01/2003 19:36:16
Mensagens: 1231
Localização: Curitiba - PR
Offline

Chute: sera que eh por que quando a thread faz wait() ela larga os locks?


Marcio Kuchma

This message was edited 1 time. Last update was at 15/03/2005 19:17:02


E tu, Belém-Efrata, pequena demais para figurar como grupo de milhares de Judá, de ti me sairá o que há de reinar em Israel, e cujas origens são desde os tempos antigos, desde os dias da eternidade. Mq 5:2, Miquéias, 750 AC aprox.
[WWW] [ICQ]
louds
Moderador
[Avatar]

Membro desde: 29/04/2003 23:09:15
Mensagens: 4061
Localização: São Paulo
Offline

Direto do javadoc da classe:


public final void wait()
throws InterruptedException

Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. In other words, this method behaves exactly as if it simply performs the call wait(0).

The current thread must own this object's monitor. The thread releases ownership of this monitor and waits until another thread notifies threads waiting on this object's monitor to wake up either through a call to the notify method or the notifyAll method. The thread then waits until it can re-obtain ownership of the monitor and resumes execution.

This method should only be called by a thread that is the owner of this object's monitor. See the notify method for a description of the ways in which a thread can become the owner of a monitor.


Porque é assim, eu não sei.

http://www.kumpera.net/blog/
http://www.mono-project.com/
"Each individual should work for himself. People will not sacrifice themselves for the company. They come to work at the company to enjoy themselves."
Soichiro Honda
[ICQ]
 
Índice dos Fóruns » Java Avançado
Ir para:   
Powered by JForum 2.1.8 © JForum Team