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.
...
In Effective Java (page 275), there is this code segment:
...
for (int i = 0; i < concurrency; i++) {
executor.execute(new Runnable() {
public void run() {
ready.countDown();
try {
start.await();
action.run();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
...
Let us suppose that I have a thread that consumes items produced by another thread. Its run method is as follows, with inQueue being a BlockingQueue
boolean shutdown = false;
while (!shutdown) {
try {
WorkItem w = inQueue.take();
w.consume();
} catch (InterruptedException e) {
shutdown = true;
}
}
...
The following program demonstrates the problem (latest JVM & whatnot):
public static void main(String[] args) throws InterruptedException {
// if this is true, both interrupted and isInterrupted work
final boolean withPrint = false;
// decide whether to use isInterrupted or interrupted.
// if this is true, the program n...
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 q...
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.Interrupted...
When I was searching for a distinction between Exceptions and Interrupts,
I found this question Interrupts and exceptions on SO...
Some answers there were not suitable (at least for assembly level):
"Exception are software-version of an interrupt" But there exist software interrupts!!
"Interrupts are asynchronous but exceptions are s...
I have an application with a JOGL component. When it shuts down using System.exit(0), I frequently get the exception:
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.Dispose...
As the Intel Manual illustrated, both Interrupt Gate and Trap Gate can be used to access a handler routine. And some exceptions even share vector numbers with interrupts. I am wondering when such a shared vector is detected by the CPU, how could CPU know whether it stands for an exception or an interrupt?
I am kind of confused about th...
Hi
I was just wondering if I have a touchscreen device that has an onTouchListener, will current execution of a method switch immediately to that listener method when the screen is touched, and could this be used to trigger an interrupted exception of a try catch block.
For example, if I have a method that does something and then reduc...
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 use...