我们正在使用Future
超时来完成任务。TimeOutException
当时间限制超过时,我们得到一个。从 的行为thread dump
,我意识到底层线程仍在继续。
是这样吗?它如何处理漫游的多个线程?如果IOException
从池中删除的线程抛出 no 怎么办?
如果这是真的,那么kill
底层线程的方法是什么。IO
在我的情况下,它一直在等待外部。
线程转储的一部分:
Thread 29587: (state = IN_NATIVE)
- java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
- java.net.SocketInputStream.read(byte[], int, int) @bci=84, line=129 (Compiled frame)
- java.io.BufferedInputStream.fill() @bci=175, line=218 (Compiled frame)
- java.io.BufferedInputStream.read1(byte[], int, int) @bci=44, line=258 (Compiled frame)
- java.io.BufferedInputStream.read(byte[], int, int) @bci=49, line=317 (Compiled frame)
- sun.net.www.MeteredStream.read(byte[], int, int) @bci=16, line=116 (Compiled frame)
- java.io.FilterInputStream.read(byte[], int, int) @bci=7, line=116 (Compiled frame)
- sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(byte[], int, int) @bci=4, line=2672 (Compiled frame)
- javax.imageio.stream.FileCacheImageInputStream.readUntil(long) @bci=64, line=121 (Compiled frame)
- javax.imageio.stream.FileCacheImageInputStream.read(byte[], int, int) @bci=69, line=167 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(long, boolean, boolean) @bci=0 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(boolean) @bci=12, line=532 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly() @bci=92, line=277 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(int) @bci=41, line=409 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(int, boolean) @bci=2, line=525 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(int, javax.imageio.ImageReadParam, boolean) @bci=3, line=968 (Compiled frame)
- com.sun.imageio.plugins.jpeg.JPEGImageReader.read(int, javax.imageio.ImageReadParam) @bci=8, line=948 (Compiled frame)
- javax.imageio.ImageIO.read(javax.imageio.stream.ImageInputStream) @bci=55, line=1422 (Compiled frame)
- javax.imageio.ImageIO.read(java.net.URL) @bci=42, line=1374 (Compiled frame)
一旦 TimeOutException 发生(对于循环中的任何任务),我们将取消这些任务,如下所示:
for(Entry<Requests, Future<?>> futureTask : futureTasks.entrySet())
{
Future<?> future = futureTask.getValue();
if(!future.isDone() || future.isCancelled())
{
future.cancel(true);
}
}
不应该解决问题吗?
请指教。
提前致谢。