草庐IT

InterruptedException

全部标签

java - Guava :Throwables.propagate 和 InterruptedException

在Guava中使用Throwables.propagate(e)时处理InterruptedException的最佳实践是什么?我喜欢使用throwThrowables.propagate(e),尤其是在不抛出已检查异常以及调用者负责异常处理的方法中。但它并没有达到我对InterruptedException的预期。我不想失去线程被中断的事实,所以我最终写了这样的东西:publicvoidrun(){Callablec=...;try{c.call();}catch(InterruptedExceptione){Thread.currentThread().interrupt();th

java - JDK8 CompletableFuture.supplyAsync如何处理interruptedException

CompletableFuture.supplyAsync(()->{transporter.write(req);//heretakethevaluefromablockingqueue,willthrowainterruptedExceptionreturnresponseQueue.take();},executorService);常见的处理interruptedException的方法要么是再次中断要么直接抛出interruptedException,但是两者都行不通。有人知道吗? 最佳答案 我这样修改代码。Complet

java - 在 Thread.join() 之前调用 Thread.interrupt() 会导致 join() 立即抛出 InterruptedException 吗?

基本上,就是问题标题所说的内容。Threadt=newThread(someRunnable);t.start();t.interrupt();t.join();//doesanInterruptedExceptiongetthrownimmediatelyhere?从我自己的测试来看,似乎是这样,但只是想确定一下。我猜Thread.join()在执行其“等待”例程之前检查线程的interrupted状态? 最佳答案 DoescallingThread.interrupt()beforeaThread.join()causethej

android - 调试Android应用程序时出现InterruptedException

在AndroidStudio中调试时,在某些情况下应用会崩溃并出现以下异常:08-2718:01:25.14419241-24656/?E/AndroidRuntime﹕FATALEXCEPTION:pool-7-thread-1Process:com.callsign.android.dev,PID:19241java.lang.InterruptedExceptionatjava.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.reportInterruptAfterWait(AbstractQueu

Android Studio 调试器应用程序崩溃并出现 InterruptedException

今天工作时,我好像突然不能再调试我们的应用程序了。有趣的是,如果我正常运行该应用程序,它会正常工作。澄清一下,我整个早上都在运行调试器,没有发生任何事故(除了偶尔的故障或崩溃)。然后午饭后它开始失败100%的时间。当然,我整天都在进行更改,因此上面的“似乎”。所以,这里有一些相关的细节:AndroidStudio2.1.1(2016年4月28日版本)此应用程序以登录屏幕启动。然后,用户必须使用调用外部服务的用户名/密码进行身份验证。我可以进入登录屏幕,但应用程序总是会在身份验证过程中的同一点崩溃。这是堆栈跟踪:05-2414:56:25.7642399-2745/com.mycomp.

java - Future.get() 在什么情况下会抛出 ExecutionException 或 InterruptedException

我的代码片段:ExecutorServiceexecutor=Executors.newSingleThreadExecutor();try{Taskt=newTask(response,inputToPass,pTypes,unit.getInstance(),methodName,unit.getUnitKey());Futurefut=executor.submit(t);response=fut.get(unit.getTimeOut(),TimeUnit.MILLISECONDS);}catch(TimeoutExceptione){//ifthetaskisstillrun

java - 如果我不是,谁在调用 Java 线程的 interrupt() 方法?

我读了又读JavaConcurrencyinPractice,我读了几个关于这个主题的线程,我读了IBM文章DealingwithInterruptedException但是有一些我根本没有理解的东西,我认为可以分为两个问题:如果我自己从不中断其他线程,那么什么会触发InterruptedException?如果我自己从来没有使用interrupt()中断其他线程(比如说因为我正在使用其他方式来取消我的工作线程,例如毒丸和while(!cancelled)样式循环[正如JCIP中所解释的]),那么InterruptedException是什么意思?抓到一只我该怎么办?关闭我的应用程序?

java - 如果我不是,谁在调用 Java 线程的 interrupt() 方法?

我读了又读JavaConcurrencyinPractice,我读了几个关于这个主题的线程,我读了IBM文章DealingwithInterruptedException但是有一些我根本没有理解的东西,我认为可以分为两个问题:如果我自己从不中断其他线程,那么什么会触发InterruptedException?如果我自己从来没有使用interrupt()中断其他线程(比如说因为我正在使用其他方式来取消我的工作线程,例如毒丸和while(!cancelled)样式循环[正如JCIP中所解释的]),那么InterruptedException是什么意思?抓到一只我该怎么办?关闭我的应用程序?

java - Java的Thread.sleep什么时候抛出InterruptedException?

Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt

java - Java的Thread.sleep什么时候抛出InterruptedException?

Java的Thread.sleep什么时候抛出InterruptedException?忽略它是否安全?我没有做任何多线程。我只想等待几秒钟再重试一些操作。 最佳答案 您通常不应忽略该异常。请看以下论文:Don'tswallowinterruptsSometimesthrowingInterruptedExceptionisnotanoption,suchaswhenataskdefinedbyRunnablecallsaninterruptiblemethod.Inthiscase,youcan'trethrowInterrupt