Questions tagged [interrupted-exception]
210 questions
7
votes
1 answer
InterruptedException in RxJava cache thread when debugging on Android
Sometimes when I am debugging my app, I encounter InterruptedException in RxCachedThreadScheduler-1. Here's the trace:
Fatal Exception: java.lang.InterruptedException
at…

mblcdr
- 762
- 9
- 18
7
votes
4 answers
Why InterruptedException is a checked exception?
This is a question on old Java when we were making our own Threads. Some methods like Thread.sleep(100) throw an InterruptedException when it is interrupted by another thread. Now as I understand, interruption means another thread is saying: Let me…

Victor
- 16,609
- 71
- 229
- 409
7
votes
2 answers
Where to catch InterruptedException for Object.wait() with synchronized block?
As I understand this is very common snippet for multithreading in Java.
boolean loaded = false;
Object lock = new Object();
public void block() {
synchronized (lock) {
while(!loaded)
lock.wait(); // Unhandled exception type…

Nikolay Kuznetsov
- 9,467
- 12
- 55
- 101
6
votes
2 answers
what happens when a thread is interrupted while blocking on a wait()?
Considering the fact that wait() can only be called in a synchronized context which subsequently release the monitor until a notify/nofityAll has been called on the same object by another thread,
Assume Thread A is blocking on a wait() which results…

arun_suresh
- 2,875
- 20
- 20
6
votes
4 answers
Interrupting looped threads in Java
I'm trying to understand how threads work in Java and currently investigating how to implement looped threads that can be cancelled. Here's the code:
public static void main(String[] args) throws Exception {
Thread t = new Thread() {
…

Andrey Agibalov
- 7,624
- 8
- 66
- 111
6
votes
3 answers
How does one correctly handle InterruptedException that may not be passed to client code?
I've stumbled upon a situation where i have to deal with InterruptedException, but can't pass it upwards and don't feel that my code should be allowed to swallow it. To be precise, i'm working on a distributed lock implementation, and request to…

Etki
- 2,042
- 2
- 17
- 40
6
votes
2 answers
How can I interrupt RestTemplate call as soon as my thread is interrupted?
I need to make a library in which I will have synchronous and asynchronous feature.
executeSynchronous() - waits until I have a result, returns the result.
executeAsynchronous() - returns a Future immediately which can be processed after other…

john
- 11,311
- 40
- 131
- 251
6
votes
5 answers
Can a synchronized block/method be interrupted?
While I know the theoretical differences between Re-EntrantLocks and synchronized, I'm confused to the below point.
See this statement from an article on Javarevisited comparing synchronized and Lock objects:
One more worth noting difference…

Saurabh Gokhale
- 53,625
- 36
- 139
- 164
6
votes
1 answer
Why should we not swallow the InterruptedException
I am very confused and not able to understand why InterruptedException should not be swallowed.
The article from IBM says
When a blocking method detects interruption and throws InterruptedException, it clears the interrupted status. If you catch…

beinghuman
- 2,088
- 7
- 27
- 36
5
votes
2 answers
Interrupting an assembly instruction while it is operating
When an interrupt comes to CPU, it is handled by saving current address location prior jumping into the handler if it is acknowledged. Otherwise it is ignored.
I wonder whether an assembly instruction call is interrupted.
For example,
mvi a, 03h ;…

Soner from The Ottoman Empire
- 18,731
- 3
- 79
- 101
5
votes
3 answers
Does Thread.sleep throw if the thread was already interrupted?
Given a thread which was interrupted while it was not blocked (i.e. no InterruptedException was thrown), does that thread throw an InterruptedException when it later attempts to sleep?
The documentation does not state this…

mafu
- 31,798
- 42
- 154
- 247
5
votes
2 answers
Should I Thread.currentThread.interrupt() before I throw an exception back?
I am implementing an interface which throws IOException. In my implementation, I call another method which can block, and therefore throw InterruptedException.
Context:
I want to end the treatment if I am interrupted;
this is not a thread I created…

fge
- 119,121
- 33
- 254
- 329
5
votes
2 answers
Future.cancel() method is not working
The code that I have creates a Callable instance and using ExecutorService a new thread is being created. I want to kill this thread after certain amount of time if the thread is not done with its execution. After going through the jdk documentation…

Ismail Shaik
- 186
- 1
- 2
- 5
4
votes
1 answer
Java: if joining Threads does not work: break or continue?
what is recommended to do if joining threads does not work?
for (List t : threads) {
try {
t.join();
} catch (InterruptedException e) {
log.error("Thread " + t.getId() + " interrupted: " +…

nano7
- 2,455
- 7
- 35
- 52
4
votes
4 answers
What might be the purpose of sleeping for just to see if the thread gets interrupted?
I came across some Java code that has a method containing the following:
static boolean waitForSeconds(long seconds) {
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException ex) {
return false;
}
return…

Anonymous
- 3,334
- 3
- 35
- 50