title: How to handle timeout a method in java?
body: <p>I am calling a method in which there is loop which will end only if it find some results otherwise it keeps on looping until it find</p>
  
  <pre><code>public Collection&lt;Serializable&gt; searchItems(Collection&lt;String&gt; tags) {
      Collection&lt;Serializable&gt; answers = (Collection&lt;Serializable&gt;) 
          this.issueParallelOperation(tags, RemoteOperation.getIndex, 
          null, null, null, null, AggregationStrategy.joinCollection);
  }
  </code></pre>
  
  <p>The code inside the method this.issueParallelOperation() keeps on looping until it find the result. I want to stop the operation after 1 min and set the <strong>answers</strong> value manually like null. I cant make changes inside this.issueParallelOperation() method as it is called by many other methods. Can anyone please suggest me some ideas how to solve this issue in this <strong>searchItems()</strong> method</p>