title: How to run a Java program for a specific amount of time?
body: <p>I want to run my program on a list of files. But a few files take much longer than expected time. So I want to kill the thread/process after the timeout period, and run the program on next file. Is there any easy way to do it? I'll be running only one thread at a time. </p>
  
  <p>Edit1:</p>
  
  <p>I am sorry I couldn't make it clear earlier. Here is the <code>for</code> loop code.</p>
  
  <pre><code>for (File file : files)
  {
    //Perform operations. 
  
  }
  </code></pre>
  
  <p>So a file is Java program file which can contain many methods. If the number of methods are less, my analysis works fine. If there are many say 20 methods, it keeps executing and analyzing them for a few hours. So in the latter case, I would like to finish that execution and go for the next java file. </p>
  
  <p>And I don't have any constraint of single threading. If multi-threading works, it's still good for me. Thanks.</p>