title: Do operation when thread dies
body: <p>I am using ThreadPoolExecutor, and need to associate workerID with each thread, so when a thread dies, that ID should be removed and when new thread is created that ID should be used. But how do I ensure that the thread died. and perform something.</p>
  
  <p>Can not rely on run method completion, as keepAliveTime is 15 minutes.</p>
  
  <p><strong>Is there any way to ensure this?</strong></p>
  
  <p><code>ThreadFactory</code> newThread method is like this :</p>
  
  <pre><code>public Thread newThread(Runnable r)
  {
      Thread thread = new Thread(group, r, (new StringBuilder()).append(namePrefix).append(threadNumber.getAndIncrement()).toString(), 0L);
      if(thread.isDaemon())
      {
          thread.setDaemon(false);
      }
  
      thread.setName((new StringBuilder()).append("Thread name : ").append(name).append(" WorkerId : ").append(getNextWorkerID());
      return thread;
  }
  </code></pre>
  
  <p><code>getNextWorkerID</code> returns newxtWorkerID.</p>