Used for thread control You are using "CountDownLatch", and at the end you are using "latch.countDown()" to control the thread. But if I use "return" to detach a thread during execution like below code, Since "latch.countDown()" cannot be called, the thread remains waiting. So I want to use "latch.countDown()" and "Thread.currentThread().interrupt()" instead of "return", but I'm wondering if this is the correct way to do it. I'd like some help on what to do if I'm wrong.
CountDownLatch latch = new CountDownLatch();
public void run() {
//....
if (isNotExist) {
retrun; //-> instead of "return" Can I use "latch.countDown()" and "Thread.currentThread().interrupt()" together?
}
//...
latch.countDown()
}