title: How to restart thread in java?
body: <p>I have created a program which searches for files in a source folder. If it finds any file, it processes that file and moves it to a destination folder, then looks for a new file in the source folder. It has to keep on checking the source folder for a file.</p>
  
  <p>I have used a thread to look for files in the source folder. The problem I am facing is whenever any exception is thrown during file processing, the thread gets stopped. I want the thread to be running even if an exception is thrown. It has to move the file that caused the error to some other folder and look for a new file in the source folder. How can I make the thread keep on running?</p>
  
  <p>Eg:</p>
  
  <pre><code>public void run() {
      try {
          searchfile();
      }
      catch(Exception e) {
          e.printStackTrace();
      }
  }
  
  public void searchfile(){
    ...
  }
  </code></pre>
  
  <hr>
  
  <p><em>Update</em> : </p>
  
  <p>I should be more clear in my question. Actually there are 4 source folders and 4 destination folders. I have to perform the same operation in each source &amp; destination pair. So i have created 4 threads in one class and do the operation in separate class.</p>
  
  <pre><code>class MainClass
  {
     public static void main(String[] args){
        for(int i=0;i&lt;4;i++){
           SearchClass search = new SearchClass();
           Thread thread = new Thread(search);
           thread.start();
       }
     }   
  }
  
  class SearchClass
  {
     public void run() {
     try {
        searchfile();
     } catch(Exception e) {
        e.printStackTrace();
     }
  }
  
  public void searchfile(){ ... } }
  </code></pre>
  
  <p>All the thread wont stop running eventhough it caught any exception in middle. How can i do that?</p>