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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:10:13+00:00 2026-06-10T12:10:13+00:00

I have a main process main . It creates 10 threads (say) and then

  • 0

I have a main process main. It creates 10 threads (say) and then what i want to do is the following:

while(required){
Thread t= new Thread(new ClassImplementingRunnable());
t.start();
counter++;
}

Now i have the list of these threads, and for each thread i want to do a set of process, same for all, hence i put that implementation in the run method of ClassImplementingRunnable.

Now after the threads have done their execution, i wan to wait for all of them to stop, and then evoke them again, but this time i want to do them serially not in parallel.

for this I join each thread, to wait for them to finish execution but after that i am not sure how to evoke them again and run that piece of code serially.
Can i do something like

for(each thread){
t.reevoke(); //how can i do that.
t.doThis();  // Also where does `dothis()` go, given that my ClassImplementingRunnable is an inner class.
}

Also, i want to use the same thread, i.e. i want the to continue from where they left off, but in a serial manner.
I am not sure how to go about the last piece of pseudo code.
Kindly help.
Working with with java.

  • 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-10T12:10:14+00:00Added an answer on June 10, 2026 at 12:10 pm

    You can’t restart a thread.

    What you could do is use the java.util.concurrent package to wait for the threads to finish and rerun you runnables in the main thread to run them sequentially – by putting your runnables in a list, you can access them during the sequential run.

    ExecutorService executor = Executors.newFixedThreadPool(10);
    List<Runnable> runnables = new ArrayList<Runnable> ();
    
    for (int i = 0; i < 10; i++) {
        Runnable r = new ClassImplementingRunnable();
        runnables.add(r);
        executor.submit(r);
    }
    
    executor.shutdown();
    //wait until all tasks are finished
    executor.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
    
    //re run the tasks sequentially
    for (ClassImplementingRunnable r : runnables) {
        //the method below can access some variable in 
        //your ClassImplementingRunnable object, that was 
        //set during the first parallel run
        r.doSomethingElse(); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one 'main' thread that creates an array of objects of class SlowData
In my sample application, I have basically two threads. The main thread contains a
I have a problem about main threads and other threads in the same process.
I'm following the example given in http://www.blog.pythonlibrary.org/2010/05/22/wxpython-and-threads/ I have a thread which is checking
I have a Main C program that creates two threads and each of those
I have main categories and sub categories. I want to be able to sort
I have main.cpp (including main function) and func1.cpp, and I want to link these
I have a java class that creates a process, called child, using ProcessBuilder. The
We have an application that creates several threads using the pthread library. As we
I have a program who run as zombie process. I want to debug it.

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.