Thank for your reply. If I would have kept on reading right away I would have found the answer on the question, and I was right. I was just a little bit confused when they didn't say that right away. If you're interested in the example the code is (I added a comment where I think the thread could get stuck):
class ThreadA {
public static void main(
String [] args) {
ThreadB b = new ThreadB();
b.start();
synchronized(b) {
try {
System.out.println("Waiting for b to complete...");
b.wait(); // This could cause the main thread to wait forever
} catch (InterruptedException e) {}
System.out.println("Total is: " + b.total);
}
}
}
class ThreadB extends Thread {
int total;
public void run() {
synchronized(this) {
for(int i=0;i<100;i++) {
total += i;
}
notify();
}
}
}
--Tomas