Olá pessoal,
estou fazendo alguns testes com Thead e me deu esse erro e não estou visualizando o erro por que está dando.
Pois estou querendo rodar um processo mas aguardar o outro para dar o resultado…
Se alguem puder me ajudar agradeço…
public class Tab extends Thread {
int contador = 0;
public synchronized void run(){
for(int x=0;x<10;x++){
contador +=x;
}
notifyAll();
}
public static void main(String [] args) {
Tab c = new Tab();
new Tab1().start();
// new Tab1().start();
// new Tab1().start();
c.start();
}
}
class Tab1 extends Thread{
Tab t;
public void run(){
synchronized(t){
try{
System.out.println("Wait...");
t.wait();
}catch (InterruptedException e) {}
System.out.println("Total is: " + t.contador);
}
}
}
erro:
Exception in thread "Thread-1" java.lang.NullPointerException
at certificacao.licão_10_Thread.Tab1.run(Tab.java:35)