Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am very sorry but I am afraid that your code that checks that service is started has bug. This code is running very quickly, starts server socket and immediately closes it. If you mean that this thread should exit when process is started listening to the same port it is wrong. Your process has 50% of chance to start successfully and other 50% to fail because when it is trying to start listening to the port your watch dog is listening to the same port itself. </p> <p>So, I believe that you should try to run process using ProcessBulder (exactly as you are doing) and then start delayed watchdog task that tries to <strong>connect</strong> to this port, i.e.</p> <pre><code>private boolean isServiceRunning() { int port = 123; try { new Socket("localhost", port).close(); return true; } catch (IOException e) { return false; } } </code></pre> <p>This method should be called from separate thread. The best way to implement thread is to use some tool that does it for you. In this case java.util.Timer is the best choice. I am suggesting to run periodic task that will call our method isServiceRunning() and cancel itself if result is true:</p> <pre><code> new Timer().schedule(new TimerTask() { @Override public void run() { if(isServiceRunning()) { this.cancel(); } } }, new Date(), 10000); </code></pre> <p>But if this solution is not good for you I'd suggest you to implement interthread communication using wait() and notfify(). Do not forget that both must be in synchronized block. Good luck!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload