title: Best practice for running a process in background and wait until it's ready
body: <p>The system:</p>
  
  <ul>
  <li>Backend Application (RESTful HTTP API) written in Java (Play Framework 2.3.x)</li>
  <li>Frontend Application (GUI, consuming the API) written in Javascript (angularjs with grunt for building)</li>
  <li>Travis CI is used for Continous Integration</li>
  </ul>
  
  <p>The problem:</p>
  
  <p>I want to start / run the backend application and after it's successfully started, I want to test it with protractor (through grunt tasks).</p>
  
  <p><strong>But</strong> starting the backend application will not continue because it is not a ending process (the server is running -> not ending)</p>
  
  <p>Putting the server start as a backend process by adding a <code>&amp;</code> could solve the problem, but then there is no guarantee that the server has started in the meanwhile.</p>
  
  <p>Some advices in the internet say: </p>
  
  <blockquote>
    <p>Add sleep(x) and run your test after that</p>
  </blockquote>
  
  <p>But how much is x?</p>
  
  <p><strong>Is there another way to do that, rather than guessing (or measuring) the time to start the server and put a sleep after running the server start as background process?</strong></p>
  
  <p>Edit:
  The output of starting the server (for example to compare the output of the background task in a periodic way) is this:</p>
  
  <pre><code>$ activator run
  [info] Loading project definition from ...
  [info] Set current project to ... (in build file:...)
  
  --- (Running the application, auto-reloading is enabled) ---
  
  [info] play - Listening for HTTP on /0:0:0:0:0:0:0:0:9000
  
  (Server started, use Ctrl+D to stop and go back to the console...)
  </code></pre>