title: Java Timeout Line of code calling soap connection
body: <p>Hello I am executing a soap request. I want to run this line of code. </p>
  
  <p>int flag=5seconds;</p>
  
  <p>//the line below doesnt come back within 5 seconds) cancel the 3rd party api call using soap and just continue</p>
  
  <p>if(time for 5 seconds)
  this.soapResponse = soapConnection.call(createSOAPRequest(value), url);</p>
  
  <p>else
  terminate and continue with rest of code.</p>
  
  <p>I need to store the soapResponse so calling other functions or classs that can allow me to pass the object back would be bad. I want a simple way of making sure that the line executes within the time set by a flag.
  Could I create a thread and wait that 5 seconds. if it doesnt come back then just end the while loop</p>
  
  <pre><code>while(count to 5 seconds){
      this.soapResponse = soapConnection.call(createSOAPRequest(value), url);
  }
  </code></pre>