|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Member
Iscritto dal: Sep 2005
Messaggi: 37
|
[java] Priorità
Ciao a tutti..
nel mio programma ho 4 thread, vorrei implementare un metodo che aumenta di uno la priorità di un singolo thread ogni volta che va in wait().. Come potrei fare? io ho provato con questo metodo: Codice:
public void aumentaPriorita() {
Thread.currentThread().setPriority(Thread.currentThread().getPriority() + 1);
Main.log.writeINF("AUMENTATA PRIORITA' a thread " + Thread.currentThread().getName() + " " + Thread.currentThread().getPriority() + ">");
}
Ultima modifica di raniero : 04-05-2006 alle 00:33. |
|
|
|
|
|
#2 |
|
Senior Member
Iscritto dal: Nov 2004
Città: Tra Verona e Mantova
Messaggi: 4553
|
Dovrebbe andare con:
Codice:
...in un blocco sincronizzato
boolean paused = false;
while(condizioneAttesa) {
try {
wait();
paused = true;
} catch(InterruptedException ex) {
//attesa interrotta
}
}
if(paused) {
Thread t = Thread.currentThread();
int priority = t.getPriority();
if(priority < Thread.MAX_PRIORITY) {
t.setPriority(priority + 1);
}
}
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 15:40.



















