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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:50:51+00:00 2026-06-10T21:50:51+00:00

I have class A in which i have two methods defined ValidateA and ValidateB

  • 0

I have class A in which i have two methods defined ValidateA and ValidateB

class A {
   ValidateA() {
        /////
    }

   ValidateB() {
        ////
    }
}

I want to run both these steps in parallel at same time and get there combined status. How can i proceed using threads?

  • 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-10T21:50:52+00:00Added an answer on June 10, 2026 at 9:50 pm

    It is always recommended to make use of the great Executors classes introduced in Java 5. They help you manage your background tasks and hides the Thread code from your classes.

    Something like the following would work. It creates a thread-pool, submits 2 Runnable classes which each call one of the validate methods, and then waits for them to finish and return. It uses a Result object that you will have to make up. It could also be a String or Integer and depends on what the validate methods return.

    // reate an open-ended thread pool
    ExecutorService threadPool = Executors.newCachedThreadPool();
    // since you want results from the validate methods, we need a list of Futures
    Future<Result> futures = new ArrayList<Result>();
    futures.add(threadPool.submit(new Callable<Result>() {
        public Result call() {
           return a.ValidateA();
        } 
    });
    futures.add(threadPool.submit(new Callable<Result>() {
        public Result call() {
           return a.ValidateB();
        } 
    });
    // once we have submitted all jobs to the thread pool, it should be shutdown,
    // the already submitted jobs will continue to run
    threadPool.shutdown();
    
    // we wait for the jobs to finish so we can get the results
    for (Future future : futures) {
        // this can throw an ExecutionException if the validate methods threw
        Result result = future.get();
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that instantiates two classes which implement interfaces. I want one
I have two PHP apps which have twho class with the same name. -
I have a class with two methods defined in it. public class Routines {
I have a class which has two HashSet<String> collections as private members. Other classes
I have a class Field of which there are two sub-classes AccountField and DecimalField
I would like to have a class B which can be extended with two
I have a IEnumerable. I have a custom Interval class which just has two
I have a web application and two class files, First class is MyClass.class which
I have a base class, B, which has two constructors, one with no paremeters
I have an abstract class Airplane, and two classes PassengerAirplane and CargoAirplane, which extend

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.