SQLiteQueue responds to InterruptedException

Issue #58 wontfix
Former user created an issue

Originally reported on Google Code with ID 58

In the sqlite4java v282, the SQLiteQueue responds to InterruptedException by simply
logging it and then ignore it through reincarnating a new SQLiteQueue thread.

The following is the code:

  private void runQueue() {
    try {
      queueFunction();
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      Internal.logWarn(this + " interrupted", e);
    } catch (Throwable e) {
      Internal.log(Level.SEVERE, this, "error running job queue", e);
      if (e instanceof ThreadDeath)
        throw (ThreadDeath)e;
    } finally {
      threadStopped();
    }

And from the above code, we can see that a queue thread only exits when a ThreadDeath
error is catched. However, AFAIK the normal way to throw such an error is through thread.stop()
which is deprecated.

I suggest treating the InterruptedException as the same as ThreadDeath, because I feel
it's more common in practice that an InterruptedException is treated as a request of
terminating yourself.

Reported by slxu@cs.washington.edu on 2014-03-02 05:20:39

Comments (2)

  1. Igor Sereda
    Thanks for your observations. In fact, the queue thread is reincarnated in all cases,
    even if ThreadDeath is caught. 
    
    This is an intentional design decision. Thread.interrupt() is performed on a specific
    thread - and it is processed correctly, by terminating the interrupted thread. 
    
    However, sending interrupt to the queue thread does not mean that the queue must stop.
    ("Queue Thread" does not equal "SQLiteQueue".) In fact, this would be a bad behavior
    because any code in your JVM can interrupt any thread (and is allowed to do so), thus
    compromising the consistency of the queue behavior. That's why the queue thread gets
    reincarnated after a while to continue serving the queue.
    
    If you need to stop the queue and terminate the thread, you need to use SQLiteQueue.stop().
    

    Reported by sereda on 2014-03-06 10:32:59

  2. Former user Account Deleted

    Reported by sereda@almworks.com on 2014-09-21 18:28:59 - Status changed: WontFix

  3. Log in to comment