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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:15:20+00:00 2026-06-13T21:15:20+00:00

I want a method that runs 2 or more methods in separate threads .

  • 0

I want a method that runs 2 or more methods in separate threads. I want be sure that method won’t finish before all threads are done.

  • 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-13T21:15:21+00:00Added an answer on June 13, 2026 at 9:15 pm

    The best approach is to utilize the Executor Service API to manage a thread pool instead of starting an open-ended number of threads on your own.

    ExecutorService pool = Executors.newCachedThreadPool();
    for (Runnable r : new Runnable[] {
        new R() { void r() { myMethod1(); }},
        new R() { void r() { myMethod2(); }},
    })
      pool.execute(r);
    pool.shutdown();
    pool.awaitTermination(60, TimeUnit.SECONDS);
    

    abstract class R implements Runnable
      public final void run() { r(); }
      abstract void r();
    }
    

    Note that it is not advisable to insist on every method running in its own, separate thread. Threads are quite heavyweight (each allocating a complete call stack) and performance actually decreases as the thread count increases far beyond the number of available processor cores.

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

Sidebar

Related Questions

I want two special methods: one that runs for all URLs one that runs
I want to write a method that run multiple threads and I want before
I want a method that extracts the data from a JSON-object parsed before as
This code isn't localized: Enum.GetNames(typeof(DayOfWeek)) I want a method that returns a list of
I want to create a method that reads a directory and finds and saves
I want to implement a method that will enable me to find a node
I want to make a method that takes any file and reads it as
I want to define a method that take an integer as input and creates
I want to create a method that takes two variables timeIn and timeOut and
i want to call a method that placed in tag in master page like

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.