Questions tagged [interrupted-exception]

210 questions
430
votes
7 answers

Handling InterruptedException in Java

What is the difference between the following ways of handling InterruptedException? What is the best way to do it? try{ //... } catch(InterruptedException e) { Thread.currentThread().interrupt(); } OR try{ //... } catch(InterruptedException…
softwarematter
  • 28,015
  • 64
  • 169
  • 263
131
votes
8 answers

When does Java's Thread.sleep throw InterruptedException?

When does Java's Thread.sleep throw InterruptedException? Is it safe to ignore it? I am not doing any multithreading. I just want to wait for a few seconds before retrying some operation.
Manki
  • 3,779
  • 4
  • 25
  • 18
51
votes
3 answers

InterruptedException when debugging Android app

When debugging in Android Studio, in certain scenarios the app crashes with following exception: 08-27 18:01:25.144 19241-24656/? E/AndroidRuntime﹕ FATAL EXCEPTION: pool-7-thread-1 Process: com.callsign.android.dev, PID:…
Marcel Bro
  • 4,907
  • 4
  • 43
  • 70
51
votes
8 answers

Is it OK to ignore InterruptedException if nobody calls interrupt()?

If I create my own thread (i.e. not a threadpool) and somewhere I call sleep or any other interruptible method, is it ok to ignore the InterruptedException if I know nobody else in the code is doing an interrupt on the thread. In other words, if…
Hilikus
  • 9,954
  • 14
  • 65
  • 118
44
votes
1 answer

Either re-interrupt this method or rethrow the "InterruptedException issue in sonar

In one of my method , interrupted exception and execution exception is coming. I put in try catch like this. try{ //my code }catch(InterruptedException|ExecutionException e) Log.error(" logging it"); throw new MonitoringException("it failed"…
Coderrr
  • 441
  • 1
  • 4
  • 4
42
votes
3 answers

In what cases does Future.get() throw ExecutionException or InterruptedException

My code snippet: ExecutorService executor = Executors.newSingleThreadExecutor(); try { Task t = new Task(response,inputToPass,pTypes,unit.getInstance(),methodName,unit.getUnitKey()); Future fut = executor.submit(t); …
java_geek
  • 17,585
  • 30
  • 91
  • 113
29
votes
1 answer

InterruptedException : what causes it?

There are interesting questions and answers regarding Java's InterruptedException, for example The Cause of InterruptedException and Handling InterruptedException in Java. However, none of them tells me about the possible sources of…
user1050755
  • 11,218
  • 4
  • 45
  • 56
27
votes
3 answers

How can I kill a thread? without using stop();

Thread currentThread=Thread.currentThread(); public void run() { while(!shutdown) { try { …
greeshma
  • 279
  • 1
  • 3
  • 3
27
votes
17 answers

Occasional InterruptedException when quitting a Swing application

I recently updated my computer to a more powerful one, with a quad-core hyperthreading processor (i7), thus plenty of real concurrency available. Now I'm occasionally getting the following error when quitting (System.exit(0)) an application (with a…
Joonas Pulakka
  • 36,252
  • 29
  • 106
  • 169
17
votes
3 answers

Thread with Lambda expression

I have an error at line 42 and 43 : Thread t1=new Thread(()->prod.test()); , Thread t2=new Thread(()->cons.test()); Unhandled exception type InterruptedException . If I try to quickfix it will created the try catch with an catch Exception, it will…
T4l0n
  • 595
  • 1
  • 8
  • 25
16
votes
1 answer

Android MIDI Threading InteruptedException - Aftertouch Messages

Trying to run MIDI on my Android app. I'm following the midisuite example to configure my app and it works fine with the exception of aftertouch. Whenever I try to trigger aftertouch, I run into a threading exception type InteruptedException. How…
yun
  • 1,243
  • 11
  • 30
16
votes
3 answers

Does calling Thread.interrupt() before a Thread.join() cause the join() to throw an InterruptedException immediately?

Basically, what the question title says. Thread t = new Thread(someRunnable); t.start(); t.interrupt(); t.join(); //does an InterruptedException get thrown immediately here? From my own tests, it seems to, but just wanted to be sure. I'm guessing…
14
votes
3 answers

Who interrupts my thread?

I understand what an InterruptedException does and why it is thrown. However in my application I get it when waiting for SwingUtilities.invokeAndWait() on a thread that is only known by my application, and my application never calls…
Thirler
  • 20,239
  • 14
  • 63
  • 92
14
votes
1 answer

Guava: Throwables.propagate and InterruptedException

what is the best practice for handling InterruptedExceptions when using Throwables.propagate(e) in Guava? I love using throw Throwables.propagate(e), especially in methods that throw no checked exceptions and where exception handling is the…
Aled Sage
  • 766
  • 7
  • 12
14
votes
3 answers

Need to semaphore.relase() if semaphore.acquire() gets InterruptedException?

From the Java java.util.concurrent.Semaphore docs it wasn't quite clear to me what happens if semaphore.acquire() blocks the thread and later gets interrupted by an InterruptedException. Has the semaphore value been decreased and so is there a need…
Ernie
  • 1,210
  • 1
  • 14
  • 21
1
2 3
13 14