Questions tagged [interrupted-exception]

210 questions
13
votes
3 answers

Concurrency - interrupting a Future without cancelling it

Is there any way to interrupt a Future without cancelling it? java doc API: boolean cancel (boolean mayInterruptIfRunning) Attempts to cancel execution of this task. This attempt will fail if the task has already completed, has already been…
12
votes
1 answer

Different behaviour when calling thread.isInterrupted and printing the result

I am bit confused with the behaviour of thread.isInterrupted in the program below. public class ThreadPractice { public static void main(String args[]) throws InterruptedException { Thread t = new Thread(new Runnable() { …
Kumar V
  • 1,570
  • 1
  • 12
  • 19
12
votes
3 answers

Why would you catch InterruptedException to call Thread.currentThread.interrupt()?

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…
ripper234
  • 222,824
  • 274
  • 634
  • 905
11
votes
5 answers

Why linux kernel use trap gate to handle divide_error exception?

In kernel 2.6.11.5, divide zero exception handler is set up as: set_trap_gate(0,÷_error); According to "Understanding The Linux Kernel", Intel trap gate cannot be accessed by a User Mode process. But it's quite possible that a user mode…
user1063294
  • 251
  • 3
  • 5
10
votes
5 answers

InterruptedException after cancel file open dialog - 1.6.0_26

The output from the code that follows is: java.vendor Sun Microsystems Inc. java.version 1.6.0_26 java.runtime.version 1.6.0_26-b03 sun.arch.data.model 32 os.name Windows XP os.version 5.1 os.arch x86 Input selection cancelled…
mhollander38
  • 775
  • 3
  • 11
  • 22
10
votes
2 answers

Why is thread not interrupted when sleeping in finally block

I have been looking all over MSDN and can't find a reason why Thread can not be interrupted when sleeping within finally block. I have tried aborting with no success. Is there any way how to wake up thread when sleeping within finally block? Thread…
Marek
  • 2,419
  • 6
  • 34
  • 38
10
votes
2 answers

Java interrupt thread when reading socket

Possible Duplicate: How to terminate a thread blocking on socket IO operation instantly? I have client run in thread want to read from socket in Java. But while reading, maybe I want to kill the thread. So I interrupt it, but does socket's…
10
votes
2 answers

Thread.isInterrupted doesn't work, Thread.interrupted does

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; //…
ripper234
  • 222,824
  • 274
  • 634
  • 905
9
votes
4 answers

Future.get() gets interrupted always with an InterruptedException

I have a WEIRD problem with Future.get() in Java. It returns always with an InterruptedException, however the weird thing is that the cause of the Exception is null, so I cant tell who interrupted me.. It gets even worse because I check before…
dgrandes
  • 1,187
  • 2
  • 14
  • 28
9
votes
1 answer

How do I write native code which responds to `Thread.interrupt()`?

In Java, all the standard blocking methods can be interrupted by calling Thread.interrupt(), but what if we have Java bindings wrapping a native library which does its own I/O? How then should the native code hook into the Thread and respond to…
9
votes
1 answer

Handling InterruptedException while waiting for an exit signal (bug in Android?)

I've come across the code below, and I'm wondering if it does exactly what I think it does: synchronized(sObject) { mShouldExit = true; sObject.notifyAll() while (!mExited) { try { sObject.wait(); } catch…
Thomas Calc
  • 2,994
  • 3
  • 30
  • 56
8
votes
5 answers

Under what conditions will BlockingQueue.take throw interrupted exception?

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(); …
Ryan
  • 307
  • 1
  • 3
  • 8
7
votes
1 answer

Extracting a process's exit code in the case of ThreadInterrupted

I have just created a process through an exec() call and I am now using its .waitFor() method. I need to catch an InterruptedException but I am not sure what I should place in the catch code block. I would like to receive the exit code but I won't…
fthinker
  • 646
  • 2
  • 9
  • 17
7
votes
3 answers

Which code can swallow interruptedException?

I read concurency in practice. Now I want to understand how to handle InterrruptedException Advices from book: - Propagate the exception (possibly after some task-specific cleanup), making your method an interruptible blocking method, too; or -…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
7
votes
2 answers

InterruptedException inside ExecutorService

Should we set the interrupted flag when catching an InterruptedException inside a task managed by an ExecutorService? Or should we just swallow the InterruptedException? Example: final ExecutorService service = ...; final Object object =…
user4460845
1
2
3
13 14