title: How do I stop a thread in an eclipse Job?
body: <p>I really need the help of the kind wizards on this site. I created a job in the <code>execute()</code> of my <code>AbstractHandler</code>. The job has a progress monitor and everything works fine until I try to abort the job.</p>
  
  <p>When a user clicks on the cancel button, the progress monitor screen goes off but a thread started within the job continues to run in the background. Calling <code>cancel()</code> on the job does not stop the child thread. Calling <code>interrupt()</code> does nothing either.</p>
  
  <pre><code>public Object execute(ExecutionEvent event) throws ExecutionException {
  
  
      ...
      job = new Job("Doing my job") {
  
          @Override
          protected IStatus run(IProgressMonitor monitor) {
              monitor.beginTask("Running a length thread",10);
              monitor.worked(1);
              Thread unstoppableThread; //the pain in my neck
  
  
                      try {
                          unstoppableThread = new Thread() {
                              public void run() {
  
                                  //A lengthy process
                              }
  
                          };
  
                      int i = 1;
                      while(unstoppableThread.isAlive()){
  
                          if(monitor.isCanceled()){
                              //job.cancel(); doesn't work
                              //IJobManager manager = Job.getJobManager();
                              //manager.cancel(job); doesn't work
                              //unstoppableThread.interrupt(); doesn't work too
                              return Status.CANCEL_STATUS; 
                          }
  
                          try {
                              if(i&lt;8)monitor.worked(1);
                              i++;
                              TimeUnit.SECONDS.sleep(1);
  
                          }
                          catch (InterruptedException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
  
                      }
  
  
              }finally{
                 monitor.done(); 
              }
  
              return Status.OK_STATUS; 
          }                                        //end of Job#run()
  
      };                                           //end of Job block
  
      job.setUser(true);
      job.schedule();
      return null;
      }
  </code></pre>