java: do not start another thread while current alive
<p>I have main thread with method "start". This method starts another thread, that doing long job. Method "start" can be call from another threads. How to avoid creating new threads in "start" method if already have one running and do not lock main thread? I trying use singleThreadExecutor, but it queues tasks.</p>

<p>code:
Start method:</p>

<pre><code> public void start(){
// need only one active thread
// if thread alive, avoid to start another
        t = new Thread( new Runnable() {
            public void run() {
                try {
                    Thread.currentThread().sleep(3000);     
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();      
    }
</code></pre>

<p>Simple test</p>

<pre><code>    for (int i = 0; i &lt; 100; i++) {
            Thread r = new Thread( new Runnable() {
                public void run() {
                    Helper.getInstance().start();
                }
            });
            r.start();      
   }    
</code></pre>