title: Managing threads in Grails Services
body: <p>So I have a service set up to import a large amount of data from a file the user uploads. I want to the user to be able to continue working on the site while the file is being processed. I accomplished this by creating a thread.</p>
  
  <pre><code>Thread.start {
   //work done here
  }
  </code></pre>
  
  <p>Now the problem arises that I do not want to have multiple threads running simultaneously. Here is what I tried:</p>
  
  <pre><code>class SomeService {
  
  Thread thread = new Thread()
  
   def serviceMethod() {
     if (!thread?.isAlive()) {
       thread.start {
          //Do work here
       }
     }
   }
  
  }  
  </code></pre>
  
  <p>However, this doesn't work. <code>thread.isAlive()</code> always return false. Any ideas on how I can accomplish this?</p>