ePrometeusCorsoJavaJava
testi articoli
Testi Articoli  Download
Home | Basi | Espressioni | Comandi | Classi | Ereditarieta | Eccezioni | Thread | Utilita | 
CorsoJava è ora Video! Free for all!
Clicca Qui!

Thread
Thread
Creazione
Stati
Runnable
Problema!
Perchè?
synchronized
Semafori
Osservazioni
wait notify
Attenzione
Stallo

<<< Attenzione >>>
Il ciclo while non può diventare un if
non è detto che dopo una notify() le condizioni siano soddisfatte
La notify riattiva un solo thread
Per riattivare tutti i thread in attesa si usa notifyAll()
Però è più inefficiente.
class Stack {
   int[] stack = new int[10]; int top=0;
   synchronized void push(int x) {
      while(top>stack.length)
        wait();
      stack[top++]=x;
      notify();
   }

synchronized void pop() { while(top==0) wait(); int r = stack[--top]; notify(); return r; }

}

ePrometeus s.r.l. - Web Software House & Open Source System Integrator
MILANO - SAN BENEDETTO DEL TRONTO(AP)
Contatti: info@eprometeus.com