How do I safely stop multiple threads?
<p>I have created a little example(below) on my attempt to safely stop multiple threads when a user clicks on a Stop button on the user interface.  However it seems like after this attempt, the threads still seems to be running.  Can you please point me in the right direction?</p>

<p><strong>Edit</strong></p>

<p>Thanks for the comments everyone, just to go along with the post, I have modified the code below with the volatile boolean flag, and it seems to be working fine until I do some I/O operations.<br>
If I add I/O operations, the threads seems to be running even if call fstream.close and then call the stop funtion to turn the boolean flag on... (Profiled the program to double-check that the threads were still runinning). 
Is there any other thing I need to do in order to take care of the opened files, and eventually stop the threads?<br>
Thanks again.</p>

<p><strong>Fixed and working code.</strong></p>

<pre><code>class MultiThreadExample implements Runnable {
    private static final MultiThreadExample threadObj = new MultiThreadExample();
    ArrayList&lt;Thread&gt; threadList = new ArrayList&lt;Thread&gt;();

    public static MultiThreadExample getInstance() {
      return threadObj;
    }

    public void tester() {
      File file = new File("data/");
      File[] files = file.listFiles();
      for (int i = 0; i &lt; files.length; i++) {
        Thread thread = new Thread(new ThreadedCrawler(), files[i].toString());
        thread.start();
        threadList.add(thread);
      }
    }

    public void run() {
      try {
        ProgramTester.getInstance().doSomething();          
      }
      finally { 
        do other stuff 
      }
    }


    public synchronized void stop() throws IOException {
      for (Thread threads : threadList) 
         threads.interrupt();
    }

    public void doSomething() {
      FileInputStream fstream = new FileInputStream(file);
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String inLine;
      while (((inLine = br.readLine()) != null) &amp;&amp;  !Thread.currentThread().isInterrupted()) {
        do something...
           for()...
               ....
               }
    }
}

public class GuiExample extends JFrame {
    ....
    public void mousePressed(MouseEvent e) {
      try {
        MultiThreadExample.getInstance().stop();
      }
      catch (InterruptedException e1) {
        e1.printStackTrace();
      }
    }
}
</code></pre>
