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 7309021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:39:22+00:00 2026-05-28T23:39:22+00:00

I work on a simulation system, where at each timestep, I have to simulate

  • 0

I work on a simulation system, where at each timestep, I have to simulate many models. I used a FixedThreadPool to speed up the calculation:

ExecutorService executor = Executors.newFixedThreadPool(nThread);
for (Model m : models) {
  executor.execute( m.simulationTask() );
}
executor.shutdown();
while ( ! executor.awaitTermination(10, TimeUnit.MINUTES) ) { 
  System.out.println("wait"); 
}

Now, the executor can’t be used to execute() new Tasks after calling shutdown(). Is there a way to reset the executor, so I can reuse the existing executor (and its threads) at the next simulation step?

  • 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-05-28T23:39:22+00:00Added an answer on May 28, 2026 at 11:39 pm

    You can reuse the executor service if you restructure your code somewhat.

    Collection<Callable<Integer>> tasks = new ArrayList<Callable<Integer>>(16);
    for (Model m : models) {
      tasks.add(m.simulationTask());
    }
    
    ExecutorService executor = Executors.newFixedThreadPool(nThread);
    try {
      executor.invokeAll(tasks);
    } catch(InterruptedException ie) {
      // Handle this
    }
    

    Basically you collect all your tasks, execute them, and await execution before proceeding. Of course, you could also alternatively just use a new Executor Service for each of your time steps, but at least you have options.

    Caveats: I didn’t compile the code so there might be errors. I also assumed an Integer parameter type for convenience.

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

Sidebar

Related Questions

We have a situation at work where developers working on a legacy (core) system
I have a bit of a mess of a file system here at work,
My work requires that I perform a mathematical simulation whose parameters come from a
In my work, I'm developing a Viewer client for a Offshore simulation server, using
Here is the situation: I have been called upon to work with InstallAnywhere 8,
I have a situation where I need to work with a datagrid and adding
Here's the situation. Due to the design of the database I have to work
Consider the following hypothetical people management system. Suppose each Person object belong to a
I have a receiver that listens for headset MEDIA_PAUSE_PLAY and for AUDIO_BECOMING_NOISY they work
I'm toying with the idea of writing a physics simulation software in which each

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.