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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:10:29+00:00 2026-05-15T21:10:29+00:00

We have 1000 threads that hit a web service and time how long the

  • 0

We have 1000 threads that hit a web service and time how long the call takes. We wish for each thread to return their own timing result to the main application, so that various statistics can be recorded.
Please note that various tools were considered for this, but for various reasons we need to write our own.
What would be the best way for each thread to return the timing – we have considered two options so far :-
1. once a thread has its timing result it calls a singleton that provides a synchronised method to write to the file. This ensures that all each thread will write to the file in turn (although in an undetermined order – which is fine), and since the call is done after the timing results have been taken by the thread, then being blocked waiting to write is not really an issue. When all threads have completed, the main application can then read the file to generate the statistics.
2. Using the Executor, Callable and Future interfaces
Which would be the best way, or are there any other better ways ?
Thanks very much in advance
Paul

  • 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-15T21:10:29+00:00Added an answer on May 15, 2026 at 9:10 pm

    Use the latter method.

    Your workers implement Callable. You then submit them to a threadpool, and get a Future instance for each.

    Then just call get() on the Futures to get the results of the calculations.

    import java.util.*;
    import java.util.concurrent.*;
    
    public class WebServiceTester {
    
      public static class Tester
            implements Callable {
        public Integer call() {
          Integer start = now();
          //Do your test here
          Integer end = now();
          return end - start;
        }
      }
    
      public static void main(String args[]) throws Exception {
        ExecutorService pool = Executors.newFixedThreadPool(1000);
        Set<Future<Integer>> set = new HashSet<Future<Integer>>();
        for (int i =0 ; i < 1000 i++) {
          set.add(pool.submit(new Tester()));
        }
        Set<Integer> results = new Set<Integer>();
        for (Future<Integer> future : set) {
          results.put(future.get());
        }
    
        //Manipulate results however you wish....
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several threads that write to the same int. Each thread increment the
I have 2 threads that communicate by sending files to each other. When Thread
I have a basic asynchronous task that performs a web request. The thread is
I have heard that thread cannot access controls of other threads directly. So our
I have an array of five threads. Each thread contains the same form, each
I have some long-running operations that number in the hundreds. At the moment they
I'm writing a load-testing application in Java, and have a thread pool that executes
I have 2 threads. My goal is that the first one that terminate his
Hello I have a Java application that takes an input number of operations to
I have these container objects (let's call them Container) in a list. Each of

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.