interrupted-exception

Occasional InterruptedException when quitting a Swing application

坚强是说给别人听的谎言 提交于 2019-11-28 05:50:06
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 Swing GUI) that I'm developing: Exception while removing reference: java.lang.InterruptedException java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) at sun.java2d.Disposer.run(Disposer.java:125) at

Future.cancel() method is not working

荒凉一梦 提交于 2019-11-28 01:20:29
问题 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 I've realized that Future.cancel() method can be used to stop the execution of the thread, but to my dismay its not working. Of course future.get() method is sending an interrupt to the Thread after the stipulated time (in my case its 2 seconds)

Who interrupts my thread?

白昼怎懂夜的黑 提交于 2019-11-27 23:38:11
问题 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 Thread.interrupt() on any thread, also it never passes the reference of the thread on to anyone. So my question is: Who interrupts my thread? Is there any way to tell? Is there a reason why the InterruptedException doesn't contain the name of the Thread that

InterruptedException : what causes it?

亡梦爱人 提交于 2019-11-27 23:34:54
问题 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 InterruptedException. What about OS signals like SIGTERM, SIGQUIT, SIGINT? Does pressing CTRL-C on the command line produce an InterruptedException? What else? 回答1: None of the things you list produce an InterruptedException . The only thing that can interrupt a

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

蓝咒 提交于 2019-11-27 20:46:23
问题 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 Thread.join() checks the interrupted status of the thread before doing its "wait" routine? 回答1: interrupt() interrupts the thread you interrupted, not the thread doing the interrupting. c.f. Thread.currentThread().interrupt(); t.join(); // will throw

When does Java's Thread.sleep throw InterruptedException?

会有一股神秘感。 提交于 2019-11-26 21:53:11
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. Benny Bottema You should generally NOT ignore the exception. Take a look at the following paper: Don't swallow interrupts Sometimes throwing InterruptedException is not an option, such as when a task defined by Runnable calls an interruptible method. In this case, you can't rethrow InterruptedException, but you also do not want to do nothing. When a blocking method detects interruption and throws

When does Java's Thread.sleep throw InterruptedException?

守給你的承諾、 提交于 2019-11-26 07:26:00
问题 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. 回答1: You should generally NOT ignore the exception. Take a look at the following paper: Don't swallow interrupts Sometimes throwing InterruptedException is not an option, such as when a task defined by Runnable calls an interruptible method. In this case, you can't rethrow InterruptedException, but you also

Handling InterruptedException in Java

笑着哭i 提交于 2019-11-26 01:25:26
问题 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 e) { throw new RuntimeException(e); } EDIT: I\'d like to also know in which scenarios are these two used. 回答1: What is the difference between the following ways of handling InterruptedException? What is the best way to do it? You've probably come to ask

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

浪子不回头ぞ 提交于 2019-11-25 23:45:25
问题 Thread currentThread=Thread.currentThread(); public void run() { while(!shutdown) { try { System.out.println(currentThread.isAlive()); Thread.interrupted(); System.out.println(currentThread.isAlive()); if(currentThread.isAlive()==false) { shutdown=true; } } catch(Exception e) { currentThread.interrupt(); } } } }); thread.start(); 回答1: The alternative to calling stop is to use interrupt to signal to the thread that you want it to finish what it's doing. (This assumes the thread you want to