interrupted-exception

Java interrupt thread when reading socket [duplicate]

…衆ロ難τιáo~ 提交于 2019-11-30 14:08:41
问题 This question already has answers here : Closed 8 years ago . 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 reading methods throw InterruptedException ? I didn't find. So, how can I nicely ask thread to die while it's blocking on reading socket? Thanks 回答1: It has been answered How to terminate a

Java interrupt thread when reading socket [duplicate]

孤街浪徒 提交于 2019-11-30 09:52:12
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 reading methods throw InterruptedException ? I didn't find. So, how can I nicely ask thread to die while it's blocking on reading socket? Thanks Mohamed Mansour It has been answered How to terminate a thread blocking on socket IO operation instantly? Basically, when you close() the socket, all the associated streams will close, causing all the blocked

boost::this_thread::interruption_point() doesn't throw boost::thread_interrupted& exception

懵懂的女人 提交于 2019-11-30 09:33:57
问题 I want to interrupt a thread using boost::thread interrupt(). I have the following code which doesn't throw boost::thread_interrupted& exception: int myClass::myFunction (arg1, arg2) try{ //some code here do { boost::this_thread::interruption_point(); //some other code here } while (counter != 20000); }catch (boost::thread_interrupted&) { cout << "interrupted" << endl; } If I replace boost::this_thread::interruption_point() with boost::this_thread::sleep( boost::posix_time::milliseconds(150))

InterruptedException after cancel file open dialog - 1.6.0_26

夙愿已清 提交于 2019-11-30 09:03:41
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 by user. Exception while removing reference: java.lang.InterruptedException java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(Unknown Source) at java.lang.ref.ReferenceQueue.remove(Unknown Source) at sun.java2d.Disposer.run(Unknown Source) at java.lang.Thread.run(Unknown Source) The following code shows the

Thread with Lambda expression

爷,独闯天下 提交于 2019-11-30 01:54:41
问题 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 have the same error and will try to fix it in the same way continuing to surround it with try catch. import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; interface Predicate { public void test() throws

InterruptedException after cancel file open dialog - 1.6.0_26

微笑、不失礼 提交于 2019-11-29 14:14:21
问题 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 by user. Exception while removing reference: java.lang.InterruptedException java.lang.InterruptedException at java.lang.Object.wait(Native Method) at java.lang.ref.ReferenceQueue.remove(Unknown Source) at java.lang.ref.ReferenceQueue.remove(Unknown Source) at sun.java2d

Future.cancel() method is not working

别来无恙 提交于 2019-11-29 07:46:58
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) and even the thread is receiving this interrupt but this interruption is taking place only once the

InterruptedException : what causes it?

南楼画角 提交于 2019-11-29 05:40:32
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? None of the things you list produce an InterruptedException . The only thing that can interrupt a thread is a call to Thread#interrupt() . The JLS is relatively clear on the matter, from section 17.2.3 :

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

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-28 21:35:02
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 { done.countDown(); } } } ... What's the use of catching the interrupted exception just to re-raise it? Why not just let it fly? The simple answer is that InterruptedException is a checked exception and it is not in the signature of the Runnable.run method (or the Executable.execute() method). So you have to

How can I interrupt RestTemplate call as soon as my thread is interrupted?

不羁的心 提交于 2019-11-28 12:29:52
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 things are done, if needed. Core Logic of my Library The customer will use our library and they will call it by passing DataKey builder object. We will then construct a URL by using that DataKey object and make a HTTP client call to that URL by executing it and after we get the response back as a JSON String, we will send that JSON String back to our