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

  • Home
  • SEARCH
  • 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 8582885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:24:25+00:00 2026-06-11T21:24:25+00:00

Below is the source code of the class. I wanted to verify how does

  • 0

Below is the source code of the class.

I wanted to verify how does shutdownNow() works for not submitted task. Problem I am getting in below code is shutdownNow() return List<FutureTask> and not List<Runnable> which I have submitted List<Runnable> containing submitted instance of PrimeProducer .

In Below program I wanted to get the tasks which where not executed and their state so that I can reschedule them later. name() represents just state that I want to store.

So I am not able to convert to submitted Task.

class PrimeProducer implements Runnable {
private final SynchronousQueue<BigInteger> queue;

PrimeProducer(SynchronousQueue<BigInteger> queue) {
    this.queue = queue;
}

public void run() {
    try {
        BigInteger p = BigInteger.ONE;
        queue.put(p = p.nextProbablePrime());
    } catch (InterruptedException consumed) {
        System.out.println("Safe Exit");
        Thread.currentThread().interrupt();
    }

}

public String name() {
    return "PrimeProducer";
}

public static void main(String[] args) throws InterruptedException,
        ExecutionException {
    PrimeProducer primeProducer = new PrimeProducer(
            new SynchronousQueue<BigInteger>());//SynchronousQueue just to ensure it put is blocking
    ExecutorService executorService = Executors.newFixedThreadPool(1);
    executorService.submit(primeProducer);
    executorService.submit(primeProducer);
    List<Runnable> list = executorService.shutdownNow();
    //PrimeProducer producer = (PrimeProducer) list.get(0);// Class Cast
                                                            // Exception
    FutureTask<PrimeProducer> futureTask = (FutureTask<PrimeProducer>) list
            .get(0);
            System.out.println(futureTask.isDone());//Prints false
    futureTask.get().name();//futureTask-->PrimeProducer get() hangs.


}
}

Problematic Lines

//PrimeProducer producer = (PrimeProducer) list.get(0);// Class Cast
                                                            // Exception
 FutureTask<PrimeProducer> futureTask = (FutureTask<PrimeProducer>) list
            .get(0);
 futureTask.get().name();//futureTask-->PrimeProducer get() hangs.
  • 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-11T21:24:26+00:00Added an answer on June 11, 2026 at 9:24 pm

    Try “execute” instead of “submit”.

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

Sidebar

Related Questions

The source code below is an example code snippet about my problem. I expect
Why does author think that below part of source code leads to race? Author
In the source code below, I am selecting a subset of properties from the
Given the example source code below, is it possible for someone to see the
in Linux kernel source code, I find below code: h++; pending >>= 1; It
I'd like to retrieve the image source within the below HTML code block, but
What does TEMP0_FILES below compute to? SOURCE_FILES can equal to multiple source files. Please
I've been having some difficulty in understanding the source of a problem. Below is
Update below... Ok, ive got a problem here. Im using this excellent vimeo class
I saw the Qt source code like this: class Q_CORE_EXPORT QBasicAtomicInt { public: ...

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.