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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:15:17+00:00 2026-05-18T11:15:17+00:00

I have a thread in Java which starts a HttpService . ProcessBuilder pb =

  • 0

I have a thread in Java which starts a HttpService.

ProcessBuilder pb = new ProceeBuilder(command);
Process process = pb.start();
process.waitFor();

I have another thread which checks if the service is started.

while (result != 0) {
  ServerSocket socket = new ServerSocker(port);
  socket.close();
  result = 0
  catch (BindException be) {
    result = 1;
  }
}

Now I need to somehow get information about whether the service has failed to start or it’s successfully started. I need to get this back to the Main class which started both of these threads in order to proceed. Something like

while (!started || !failed) {
     wait for getting information from the threads.
}

What can you advise?
Thank you.

  • 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-18T11:15:17+00:00Added an answer on May 18, 2026 at 11:15 am

    How about using a callback that you pass to both threads?

    (omitted try-catches)

    public class MyCallback {
      private Boolean processSuccess;
      private Boolean serviceSuccess;
      public synchronized void notifyProcessStart(boolean success) {
        this.processSuccess = success;
        this.notifyAll();
      }
      public synchronized void notifyServiceCheck(boolean success) {
        this.serviceSuccess = success;
        this.notifyAll();
      }
      public synchronized void waitForResult() {
        while(processSuccess == null || serviceSuccess == null) {
          this.wait();
        }
        // ... do something good
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a non-GUI thread that starts a JFrame using java.awt.EventQueue.invokeLater(new Runnable() { public
I have a fairly straightforward Java class here which creates 2 thread pools.... Connects
I have a java application where the main-thread starts 2 other threads. If one
I have a server in Java which is multithreading, and I've created a thread
In Java, I would do something like: Thread t = new MyThread(); t.start(); I
I'm relatively new in the Java world and I have a problem which I
I have written a service which starts a java.exe or ruby.exe (I know there
I have a Java application which is used to start a Swing user interface.
I have a Java class which starts a TimerTask in its main method, the
I have a simple class which starts 3 threads and saves a new object

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.