project_34
11-07-2006, 15:46
ciao a tutti :) sono nuovo del java e gestione dei thread e non riesco a risolvere questo problema..
Devo gestire diversi thread che effettuano richieste e un thread che le soddisfa..questo però deve avvenire una richiesta per volta (richiesta -> soddisfatta .. richiesta -> soddisfatta .. etc ..). I vari Simple_thread e il Soddisfa_thread comunicano tramite un oggetto condiviso...
class Cell {
public int array_contents[];
public int indirizzo;
private boolean available = false;
public synchronized Cell get() {
while (available == false) {
try {
wait();
}
catch(InterruptedException e) {}
}
available = false;
notifyAll();
return this;
}
public synchronized void put(int []pages,int ind) {
while (available == true) {
try {wait();} catch(InterruptedException e) {}
}
array_contents = pages;
indirizzo = ind;
available = true;
notifyAll();
}
}
Il problema è che depositata una richiesta effettuo una notifyAll() che mi risveglia tutti i thread, e non solo il Soddisfa_thread come dovrebbe avvenire.
C'è un modo per risvegliare solo quel processo, magari tramite altre funzioni che non conosco? :coffee: :cry:
Devo gestire diversi thread che effettuano richieste e un thread che le soddisfa..questo però deve avvenire una richiesta per volta (richiesta -> soddisfatta .. richiesta -> soddisfatta .. etc ..). I vari Simple_thread e il Soddisfa_thread comunicano tramite un oggetto condiviso...
class Cell {
public int array_contents[];
public int indirizzo;
private boolean available = false;
public synchronized Cell get() {
while (available == false) {
try {
wait();
}
catch(InterruptedException e) {}
}
available = false;
notifyAll();
return this;
}
public synchronized void put(int []pages,int ind) {
while (available == true) {
try {wait();} catch(InterruptedException e) {}
}
array_contents = pages;
indirizzo = ind;
available = true;
notifyAll();
}
}
Il problema è che depositata una richiesta effettuo una notifyAll() che mi risveglia tutti i thread, e non solo il Soddisfa_thread come dovrebbe avvenire.
C'è un modo per risvegliare solo quel processo, magari tramite altre funzioni che non conosco? :coffee: :cry: