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

The Archive Base Latest Questions

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

I am working on a existing code, where I found this piece of code

  • 0

I am working on a existing code, where I found this piece of code in one of the class.
The code is using ExecutorService, instead of doing MyThread.start.

Please tell me why to use ExecutorService instead of Thread.start.

protected static ExecutorService executor = Executors.newFixedThreadPool(25);

while (!reader.isEOF()) {
    String line = reader.readLine();
    lineCount++;
    if ((lineCount > 1) && (line != null)) {
        MyThread t = new MyThread(line, lineCount);
        executor.execute(t);
    }
}
  • 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-15T08:30:59+00:00Added an answer on June 15, 2026 at 8:30 am

    I suppose MyThread extends Thread and Thread implements Runnable. What you are doing in that code is submitting a Runnable to the executor, which will execute it in one of its 25 threads.

    The main difference between that and starting the threads directly with myThread.start() is that if you have 10k lines, this could start 10k threads concurrently, which would probably exhaust your resources pretty quickly.

    With the executor as it is defined, no more than 25 threads will run at any time, so if a task is submitted while all 25 threads are already in use, it will wait until one of the threads becomes available again and run in that thread.

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

Sidebar

Related Questions

Working on existing code, I recently found smt like this: if(Config.ExceptionBehavior.DEBUG_EXCEPTIONS) { foo.Foo(); }
I'm working on some existing code. After a few hours, I've boiled this problem
I am working on the redesign of an existing class. In this class about
In the existing code I am working with I have found the money transfer
I was recently modifying some code, and found a pre-existing bug on one line
I'm working on some existing c++ code that appears to be written poorly, and
I'm working on modifying some existing code for a payment gateway and I'm not
Currently, I am working on restructuring an existing code base. I'm new to php
I am working on an existing system written using .NET 2.0 remoting to integrate
I am working on existing code to enhance the functionality. In existing code 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.