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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:32:44+00:00 2026-06-09T06:32:44+00:00

I am starting multiple threads(around 1000) from my code. They are Runnable threads called

  • 0

I am starting multiple threads(around 1000) from my code. They are Runnable threads called from a while loop. How do I calculate the total time taken for all threads to finish executing?

Also I am opening a DB Connection and have a set of queries for which I am starting these threads(1 thread for 1 query). When do I close the connection?

  • 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-09T06:32:46+00:00Added an answer on June 9, 2026 at 6:32 am

    I would use an ExecutorService

    long start = System.nanoTime();
    ExecutorService service = Executors.newWhatEverPool();
    for(loop)
       service.submit(new MyRunnable());
    
    service.shutdown();
    service.awaitTermination(1, TimeUnit.HOUR); // or longer.    
    long time = System.nanoTime() - start;
    System.out.printf("Tasks took %.3f ms to run%n", time/1e6);
    

    Close the connection when you have finished with it. It is a common pattern for the creator of a resource to also close it. e.g. If the main thread creates the connection, it could close after all the threads have finished.

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

Sidebar

Related Questions

I'm performing I/O to a single file from multiple threads. Access to this shared
I have an application that has multiple threads processing work from a todo queue.
I started multiple threads by for each loop in my windows service.I didn't mention
I'm trying to read java.io.InputStream multiple times starting from the top of the stream.
On a HTML canvas I have multiple points starting from 1 to N, this
I'm just starting out refactoring my code into multiple assemblies, and feel a bit
Starting from scratch with very little knowledge of .NET, how much ASP.NET should I
Starting from scratch is hard. How do you do it? I quite like color
I am starting with multi-threads in python (or at least it is possible that
Possible Duplicate: C# Spawn Multiple Threads for work then wait until all finished 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.