title: java : execute a method over a maximum period of time
body: <p>I am using the <code>JavaMail API</code> , and there is a method in the Folder class called "search" that sometimes take too long to execute. What i want is to execute this method over a maximum period of time( say for example 15 seconds in maximum) , that way i am sure that this method will not run up more than 15 seconds.  </p>
  
  <p>Pseudo Code</p>
  
  <pre><code>messages = maximumMethod(Folder.search(),15);
  </code></pre>
  
  <p>Do I have to create a thread just to execute this method and in the main thread use the wait method ?</p>