Olá, tenho as seguintes classes:
package acordandoThreadExterna;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
public class Worker extends Thread{
ControladorStatus control;
BlockingQueue<Integer> work;
int valor;
public Worker(){
this.control = new ControladorStatus(this);
this.control.start();
this.work = new LinkedBlockingQueue<Integer>();
}
public void run() {
try {
this.valor = this.work.take();
System.out.println("RECEBI: " + this.valor);
this.atualiza();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void atualiza(){
.......
}
}
package acordandoThreadExterna;
public class ControladorStatus extends Thread{
Worker worker;
ControladorStatus (Worker worker) {
this.worker = worker;
}
public void run() {
while (true) {
this.worker.atualiza();
try {
wait(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
Eu tenho a thread ControladorStatus, esta a cada 5s irá executar o método atualiza(), eu consigo fazer com que outra thread externa ative esta mesma thread? Neste meu caso entao teria duas situação onde ela executa a cada 5s e também pode exetuar a cada 2s, 3s ou 1s