Newsgroup: it.comp.java
Titolo: Ora è proprio grave!!!AIUTO!!

Ciao a tutti sono veramente in crisi mistica, domani devo 
consegnare il progetto ma non riesco a svegliare i Threads Sospesi...
perchè mi dice IllegalMonitorStateException at
java.lang.Object.notifyAll()
questa è la porzione di codice incriminata:
------
class Pilota...
	    if (!classifica.ultimo() &&  ImTheBest) {
		        notifyAll();
			try{
			   this.wait();
				}catch (InterruptedException e) {};
		    }
		    else {if (ngiri==0) {esci=true;}};
		}
	}
----
devo risvegliare un thread Pilota che prima si era sospeso e sospendermi
a mia volta.
Il problema è che sulla notify mi dà quell'errore senza svegliare
nessuno... come mai?
questo è ciò che ho trovato su Internet.. ma nn ho capito qual è la
soluzione. Grazie a tutti!!!!
This method should only be called by a thread that is the owner of this object's monitor.
A thread becomes the owner of the object's monitor in one of three ways:
* By executing a synchronized instance method of that object.
* By executing the body of a synchronized statement that synchronizes on the object.
* For objects of type Class, by executing a synchronized static method of that class.
Only one thread at a time can own an object's monitor.
Exception: IllegalMonitorStateException if the current thread is not the owner of this object's monitor.
Voir: java.lang.Object.notifyAll()
Voir: java.lang.Object.wait()

 java.lang.Object.wait()
Per poter chiamare notify() o notifyAll() il thread deve avere il lock
sull'oggetto, il che significa che si può fare solo dall'interno di un
blocco synchronized, altrimenti il monitor dei lock (giustamente) se la
prende male :)
Spero di averti aiutato.
Ciao :-)
pole

 soluzione. Grazie a tutti!!!!
Ecco quanto riporta JavaDoc riguardo a java.lang.Object.notifyAll():
notifyAll:
     Wakes up all threads that are waiting on this object's monitor.
     A thread waits on an object's monitor by calling one of the wait methods.
     The awakened threads will not be able to proceed until
     the current thread relinquishes the lock on this object.
     The awakened threads will compete in the usual manner with
     any other threads that might be actively competing to synchronize
     on this object; for example, the awakened threads enjoy
     no reliable privilege or disadvantage in being the next
     thread to lock this object.
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.
notify:
A thread becomes the owner of the object's monitor in one of three ways:
     * By executing a synchronized instance method of that object.
     * By executing the body of a synchronized statement that synchronizes on the object.
* For objects of type Class, by executing a synchronized static method of that class.
Parla chiaro... :-)
Modifica il tuo codice in maniera da essere l'owner
dell'object monitor, nel tuo caso "this":
synchronized( this){
   if (!classifica.ultimo() &&  ImTheBest) {
     notifyAll();
       try{
  	this.wait();
       }
       catch (InterruptedException e) {
       }
   }else{
     if (ngiri==0) {
       esci=true;
     }
   }
}
Hope this helps
Luigi
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com
 - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

Ragazzi grazie mille!!!
Quando si dice ... perdersi in un bicchier d'acqua!!
Ciao a presto
