I have a thread A which runs another thread B. Thread A implements a method "stopExec()" which tries to exit thread B cleanly - allowing it to finish some tasks. So my stopExec method looks something like this:
private CountDownLatch lock;
public void stopExec() {
lock = new CountDownLatch(1);
threadB.finish();
try {
lock.await();
} catch(InterruptedExcetion ie) {
Log.d(null, "Thread A not locked.");
}
Log.d(null, "Finished.");
}
Thread B has a reference to Thread A and it calls "threadA.lock.countDown();" when it finished whatever it was doing.
What happenes it that exception is thrown...thread A doesn't wait, but simply continues. Can somebody explain me why/what am I doing wrong. I have used CountDownLatch in a similar way in other cases and it is working as expected.
Thank you!