Dúvida em synchronized

2 respostas
T
void waitForSignal() throws Exception{
		Object obj = new Object();

		synchronized( Thread.currentThread() ){

			obj.wait();
			obj.notify();
		}
	}

A) This code may throw an InterruptedException
B) This code may throw an IllegalStateException
C) This code may throw a TimeoutException after ten minutes
D) This code will not compile unless "obj.wait()" is replaced with "((Thread) obj).wait()"
E) A call to notify() or notifyAll() from another thread may cause this method to complete normally.

A resposta é a A. Porém, pra mim, esse código irá sempre lançar uma "IllegalMonitorStateException", pois o objeto colocado no synchronized não é o mesmo usado para chamar os métodos wait() e notify().

Alguém pode explicar porque a alternativa A é a correta?

Obrigado! :)

2 Respostas

ViniGodoy

Ninguém pode. Você está certo.

V

Eu ja vi essa questão e voce está certo a não ser que tenha postado as alternativas erras , a questão também esta errada !

Criado 17 de fevereiro de 2010
Ultima resposta 18 de fev. de 2010
Respostas 2
Participantes 3