I have two threads that want to synchronize the same object. Thead A should be able to abort Thread B if a certain condition has been filled. Here is some kind of pseudo-code of what these two threads do / should do.
Answer:
public void run() { while(true) {
B:
public void run() { while(true) { try {
Here is a situation that I cannot solve:
- Topic
A grabs a shared resource and does some things. - Meanwhile, Thread
B reaches the synchronized block and expects A free its shared resource. - Thread
A , doing things, realized that Thread B should not have a shared resource and was trying to abort Thread B But Thread B has already surpassed the points at which an InterruptedException could be thrown.
My question is, is there a way to interrupt a thread while it is waiting for synchronized something?
java multithreading synchronized interrupt
Eric
source share