Salve,
sto riprendendo i contatti con java e la programmazione dopo un po' di tempo che me ne ero allontanato per lavoro..
Sto facendo esercitazioncine varie, e ieri sui thred ho riscontrato questo errore a RunTime, che non riesco a risolvere:
Vi illustro il codice, non so se posso aver fatto errori di importazione o di package.. visto che utilizzo anche per le prime volte NetBeans...:Exception in thread "main" java.lang.IllegalMonitorStateException: current thread not owner
at java.lang.Object.notify(Native Method)
at it.ricca.prove.Starter.main(Starter.java:12)
codice:package it.ricca.prove; public class WaitingThreadTest implements Runnable{ String name; Object o; public WaitingThreadTest (String name, Object o){ this.name=name; this.o=o; } public void run() { synchronized(o){ try{o.wait();} catch(InterruptedException ie){} for(int i=0;i<4;i++) System.out.println("Hy!! My name is "+name+"!!!"); } } public static void main (String[] argv ) { Object ob =new Object(); Thread t1=new Thread (new WaitingThreadTest("Primo", ob)); Thread t2=new Thread (new WaitingThreadTest("secondo", ob)); Thread t3=new Thread (new WaitingThreadTest("terzo", ob)); t2.start(); t1.start(); t3.start(); //Arriva fino a stampare questa frase... System.out.println("Siamo partiti tutti!!"); //E QUESTA ULTIMA E' L'ISTRUZIONE CHE GENERA L'ERRORE ob.notify(); } } Grazie,![]()
![]()

Rispondi quotando