简体   繁体   English

以某种方式等待并抛出InterruptedException的Java方法

[英]Java methods that get to wait somehow and that throw InterruptedException

I'm looking for a list of methods that throw an InterruptedException . 我正在寻找抛出InterruptedException的方法列表。 So far, I've got sleep() & join() of Thread and wait() of Object . 到目前为止,我已经得到了Thread sleep()join()以及Object wait() Are there any others anywhere in Java that throw an InterruptedException or this is it? 在Java中是否有任何其他地方抛出InterruptedException或者这就是它?

Note: I'm not asking anything else about Java interrupts. 注意:我不是在询问有关Java中断的任何其他内容。 just looking to get the comprehensive list. 只是想获得全面的清单。

//===================================== // =====================================

EDIT: rephrasing the Q for a bit more: 编辑:重新改写Q:

"the methods that throw an InterruptedException in Java are those invoking wait() , join() and sleep() of Object and Thread . These 3 methods are the "roots" of Java interrupts." “在Java中抛出InterruptedException的方法是调用ObjectThread wait()join()sleep() 。这三种方法是Java中断的”根源“。

is this statement true? 这句话是真的吗?

For your second question about the roots of the InterruptedException s, the following classes actually generate one (ie, throw new InterruptedException(...); ). 对于关于InterruptedException的第二个问题,以下类实际生成一个(即throw new InterruptedException(...); )。 This is from my JDK (OpenJDK 1.8.0.11). 这是我的JDK(OpenJDK 1.8.0.11)。

For clarity, these are all the outer classes (ie, not inner classes) that throw a new InterruptedException somewhere, including in an inner class. 为清楚起见,这些是在某个地方抛出新的InterruptedException所有外部类(即不是内部类),包括在内部类中。 In other words, if class X has an inner class XY , and XY has a method that throws a new InterruptedException , then it will appear in this list as X . 换句话说,如果类X具有内部类XY ,并且XY具有抛出新的InterruptedException的方法,则它将在此列表中显示为X It does not include native methods that generate one (which is why java.lang.Object doesn't appear here). 包括产生一个(这就是为什么本地方法java.lang.Object不会出现在这里)。 The only two classes with native methods that throw an InterruptedException are java.lang.Object and java.lang.Thread . 使用本机方法抛出InterruptedException的唯一两个类是java.lang.Objectjava.lang.Thread

java.util.concurrent.CyclicBarrier
java.util.concurrent.LinkedTransferQueue
java.util.concurrent.ForkJoinPool
java.util.concurrent.CompletableFuture
java.util.concurrent.locks.AbstractQueuedLongSynchronizer
java.util.concurrent.locks.AbstractQueuedSynchronizer
java.util.concurrent.locks.StampedLock
java.util.concurrent.SynchronousQueue
java.util.concurrent.Phaser
java.util.concurrent.FutureTask
java.util.concurrent.Exchanger
java.util.concurrent.ForkJoinTask
java.lang.InterruptedException
com.sun.corba.se.impl.orbutil.concurrent.DebugMutex
com.sun.corba.se.impl.orbutil.concurrent.Mutex
com.sun.corba.se.impl.orbutil.concurrent.CondVar
com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex
com.sun.jmx.snmp.daemon.SnmpAdaptorServer
com.sun.jmx.snmp.daemon.CommunicatorServer

Here's the complete list of classes from my JDK that can throw one, including one that's generated at a lower level in the stack. 这是我的JDK中可以抛出一个类的完整列表,包括在堆栈中较低级别生成的类。

javax.swing.SwingWorker
javax.swing.SwingUtilities
java.nio.file.WatchService
java.nio.channels.AsynchronousChannelGroup
java.awt.MediaTracker
java.awt.image.PixelGrabber
java.awt.EventQueue
java.util.concurrent.Executors
java.util.concurrent.CyclicBarrier
java.util.concurrent.LinkedTransferQueue
java.util.concurrent.ThreadPoolExecutor
java.util.concurrent.DelayQueue
java.util.concurrent.CountDownLatch
java.util.concurrent.AbstractExecutorService
java.util.concurrent.TimeUnit
java.util.concurrent.ForkJoinPool
java.util.concurrent.LinkedBlockingDeque
java.util.concurrent.ScheduledThreadPoolExecutor
java.util.concurrent.CompletableFuture
java.util.concurrent.ExecutorService
java.util.concurrent.ExecutorCompletionService
java.util.concurrent.CompletionService
java.util.concurrent.locks.ReentrantReadWriteLock
java.util.concurrent.locks.AbstractQueuedLongSynchronizer
java.util.concurrent.locks.Lock
java.util.concurrent.locks.AbstractQueuedSynchronizer
java.util.concurrent.locks.Condition
java.util.concurrent.locks.StampedLock
java.util.concurrent.locks.ReentrantLock
java.util.concurrent.SynchronousQueue
java.util.concurrent.ArrayBlockingQueue
java.util.concurrent.LinkedBlockingQueue
java.util.concurrent.TransferQueue
java.util.concurrent.Semaphore
java.util.concurrent.BlockingQueue
java.util.concurrent.Phaser
java.util.concurrent.PriorityBlockingQueue
java.util.concurrent.FutureTask
java.util.concurrent.BlockingDeque
java.util.concurrent.Future
java.util.concurrent.Exchanger
java.util.concurrent.ForkJoinTask
java.lang.UNIXProcess
java.lang.ref.ReferenceQueue
java.lang.Process
java.lang.Object
java.lang.Thread
sun.font.CreatedFontTracker
sun.nio.fs.AbstractWatchService
sun.nio.ch.AsynchronousChannelGroupImpl
sun.nio.ch.PendingFuture
sun.misc.Lock
sun.misc.ConditionLock
sun.misc.Queue
sun.misc.VM
sun.toolsc.SourceClass
sun.awt.X11.XBaseWindow
sun.awt.X11.XSelection
sun.awt.EventQueueDelegate
sun.awt.SunToolkit
sun.awt.im.ExecutableInputMethodManager
sun.awt.shell.ShellFolder
sun.awt.AWTAccessor
sun.applet.AppletPanel
com.sun.xml.internal.ws.encoding.ImageDataContentHandler
com.sun.xml.internal.messaging.saaj.soap.ImageDataContentHandler
com.sun.corba.se.impl.orbutil.concurrent.DebugMutex
com.sun.corba.se.impl.orbutil.concurrent.Sync
com.sun.corba.se.impl.orbutil.concurrent.Mutex
com.sun.corba.se.impl.orbutil.concurrent.CondVar
com.sun.corba.se.impl.orbutil.concurrent.ReentrantMutex
com.sun.corba.se.impl.orbutil.threadpool.WorkQueueImpl
com.sun.org.apache.xml.internal.utils.ThreadControllerWrapper
com.sun.tools.sjavac.server.CompilerPool
com.sun.tools.example.debug.bdi.JDIEventSource
com.sun.tools.example.debug.bdi.ExecutionManager
com.sun.tools.example.debug.bdi.ThreadInfo
com.sun.tools.example.debug.gui.ContextManager
com.sun.tools.jdi.EventQueueImpl
com.sun.jmx.remote.internal.ArrayNotificationBuffer
com.sun.jmx.remote.internal.NotificationBuffer
com.sun.jmx.snmp.daemon.SnmpAdaptorServer
com.sun.jmx.snmp.daemon.CommunicatorServer
com.sun.jndi.ldap.EventQueue
com.sun.jdi.event.EventQueue
com.sun.swing.SwingUtilities3

I am not sure that there is a comprehensive list, but your current list is far from complete. 我不确定是否有完整的清单,但您目前的清单还远未完成。

Many of the methods in java.util.concurrent.* throw the exception. java.util.concurrent.*许多方法抛出异常。 Just look at Future which has a couple and others in that package. 看看Future ,其中包含一对和其他人。

Then there are the NIO function calls, channels, etc. There's lots (thousands). 然后是NIO函数调用,通道等。有很多(数千)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM