title: Execute a resource liberation action on Java's ThreadPoolExecutor's Thread death
body: <p>I have a Java ThreadPool that is initialized as follows:</p>
  
  <pre><code>ThreadFactory tFactory = new DatabaseWorkerThreadFactory();
  final ExecutorService dbService = new ThreadPoolExecutor(1, 5, 10L, TimeUnit.SECONDS, new ArrayBlockingQueue&lt;Runnable&gt;(10), tFactory);
  </code></pre>
  
  <p>Then execute Runnable Task on that threadpool like this</p>
  
  <pre><code>executorService.execute(new RunnableDbInsertTask(netData));
  </code></pre>
  
  <p>to get those inserts to be async from the rest of my code.</p>
  
  <p>As i'm using ActiveJDBC as an ActiveRecord implementation, I need each worker to have an active Connection, which I do having this code at the start of the <code>RunnableDbInsertTask</code>'s <code>run()</code> method:</p>
  
  <pre><code>if(!Base.hasConnection())
          Base.open(params);
  </code></pre>
  
  <p>So when the <code>ThreadPoolExecutor</code> is used, each new spawned <code>Thread</code> that gets tasks, will have a  unique connection, and will reuse it for every connection.</p>
  
  <p>Now I want the thread amount to fallback to the minimum (1), as specified in the <code>ThreadPoolExecutor's</code> constructor, when there are no jobs to be done.  </p>
  
  <p>For this to happen correctly, I need that when a Thread is automatically finished by the <code>ThreadPoolExecutor</code> because of inactivity, it auto-finishes it's connection calling ActiveJDBC's <code>Base.close()</code> method</p>
  
  <p>As a solution I tried overriding <code>DatabaseWorker.interrupt()</code> method, but that didn't worked.</p>
  
  <p>Any help appreciated. Thanks!</p>