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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:18:44+00:00 2026-05-17T01:18:44+00:00

I am confused on the following: To use threads in a Java program, the

  • 0

I am confused on the following:
To use threads in a Java program, the simplest way is to extend Thread class and implement the runnable interface (or simply implement runnable).
To start the thread’s execution. we must call the Thread’s method start(), which in turn calls method run() of the thread. And so the thread starts.
The method start() (unless I am wrong) must be called exactly and only once for each thread. As a result, thread instances can not be reused unless somehow the run method itself runs in some-short of infinite loop that facilitates a custom implementation of the thread’s reusage.
Now the javadoc
link text
says

Calls to execute will reuse previously constructed threads if available

I do not understand how this is implemented.
I provide in the execute method of the executor method my custom thread e.g.

  ExecutorService myCachedPool = Executors.newCachedThreadPool();
  myCachedPool.execute(new Runnable(){public void run(){  
     //do something time consuming

  }});

How can this custom thread I delegeate to the executor framework be reused?
Is Executor is allowed to call method start() more than 1 time, while we can not in our programs?
Am I misunderstanding something?

Thank you.

  • 1 1 Answer
  • 1 View
  • 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-17T01:18:44+00:00Added an answer on May 17, 2026 at 1:18 am

    Note that it’s not Executor that calls start() – it’s ExecutorService. And no, it’s not calling start() twice. It doesn’t start the task that you give it directly using Thread.start()… instead, it starts a thread which knows about that thread pool’s queue of work. The thread will basically wait until there’s some work to do, then pick it up and execute it, before going back to waiting. So although the thread performs several tasks, Thread.start() is only called once.

    EDIT: Judging by the comments, you’re a bit confused about the difference between a Runnable (which is a task to be executed) and a Thread (which is what executes tasks).

    The same thread can execute multiple tasks. For a very simple example not using a thread pool, consider this:

    public class MultiRunnable implements Runnable
    {
        private final List<Runnable> runnables;
    
        public MultiRunnable(List<Runnable> runnables)
        {
            this.runnables = runnables;
        }
    
        public void run()
        {
            for (Runnable runnable : runnables)
            {
                 runnable.run();
            }
        }
    }
    

    (Ignore the potential thread safety issues of using a List<T> from multiple threads.)

    You could create a whole bunch of Runnable tasks capable of doing different things, then create a single MultiRunnable to run them in turn. Pass that instance of MultiRunnable into the Thread constructor, and then when you start the thread, it will execute each of the original runnable tasks. Does that help?

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

Sidebar

Related Questions

I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
Possible Duplicate: c++ multithread I use c++ to implement a thread class. The code
I'm confused by the following code: class MyException extends Exception {} class AnotherException extends
I have read Java String class is immutable and thread-safe but I am still
I'm trying to use openssl dsa implementation, but I'm very confused with the following
I am confused on the following: I want to do: public class MyGenericClass<SomeType> extends
Coming from Java I'm confused by the use of Void allowing a return value
I'm a little bit confused with the use of @. In the following code
I am confused with following string function echo strlen(l\n2); //give 3 in output where
I am little bit confused about following problem & their solutions: i have 2

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.