Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:15:58+00:00 2026-06-17T07:15:58+00:00

We are using Future with a timeout to accomplish a task. We get a

  • 0

We are using Future with a timeout to accomplish a task. We get a TimeOutException when time limit exceeds. From the behavior of thread dump, I realize that underlying thread continues.

Is it the case? How does it take care of multiple threads roaming around?
What if no IOException is thrown for the thread which was removed from the pool?

If this is true, what is the way to kill underlying thread. It keeps on waiting for an external IO in my case.

A part of thread dump:

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)

Once TimeOutException occurs (for any task in the loop), we cancel the tasks like this:

for(Entry<Requests, Future<?>> futureTask : futureTasks.entrySet())
                {
                    Future<?> future = futureTask.getValue();
                    if(!future.isDone() || future.isCancelled())
                    {
                        future.cancel(true);
                        }
                }

Shouldn’t it solve the problem?

Please advice.

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:15:59+00:00Added an answer on June 17, 2026 at 7:15 am

    Yes, it’s the case that your thread continues and executed task is unaffected. TimeoutException indicates that you didn’t get the result in the appropriate time.

    If you want to interrupt underlying thread you can handle the exception and use cancel(true) method from the used implementation of Future.

    EDIT

    I missed the case that your thread is waiting on a blocking I/O as your stack trace explains. Thread.interrupt() which is called from future.cancel(true) won’t help in this case.

    The common pattern in this situtation is to close underlying input stream. I’m not very familiar with javax.imageio package but there is an overloaded method on ImageIO which accepts the InputStream. You might want to store it somewhere and later close it on timeout.

    It will call close() on SocketInputStream which in its turn will call close() method of underlying Socket which is waiting for blocking read to complete. An executing thread which is blocked in an I/O operation (as per your trace) upon this socket will stop waiting for EOF with SocketException.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Callable, Executor and Future objects to invoke webservices in parallel from
I have the following code: #include <iostream> #include <future> #include <chrono> #include <thread> using
I have used TaskExecutor from spring and futures to get the future from the
I realize that this problem can be solved in the future by using some
I'm running a process in a separate thread with a timeout, using an ExecutorService
I submit some some Future tasks using a CompletionService wrapped round a 2 thread
I need to get 2 as number for future using (2) <div class=pageCont> <span
I have org files in a github repository and using project pages future. Exporting
So I will be using AWS for a future project, and I have been
I'm using VCR gem to record http interactions and replay them in future. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.