How do I safely interrupt a mid flight transaction?

39 views
Skip to first unread message

Meni Hillel

unread,
Jul 4, 2019, 11:45:45 AM7/4/19
to H2 Database
Is there a way to safely interrupt a running thread, that may be in middle of a transaction commit? I read that it is not recommended to use Thread.interrupt() with h2, but I have a need to shutdown many threads and cannot tell which thread may be in middle of a transaction. The main motivation here is to prevent database corruption which I suspect is happening.

Evgenij Ryazanov

unread,
Jul 4, 2019, 12:30:37 PM7/4/19
to H2 Database
Thread.interrupt() is a way to database corruption.

Take a look on the SHUTDOWN command:
You can execute this command and wait for its completion. After its execution you can interrupt your threads as you wish.

Of course, you need to prevent allocation of new connections after this command, because a new connection can open the database again.

Meni Hillel

unread,
Jul 4, 2019, 12:45:37 PM7/4/19
to H2 Google Group
I read about SHUTDOWN and it is good if I want to tear the whole thing down.  But what if I want to interrupt a single transaction?

--
You received this message because you are subscribed to a topic in the Google Groups "H2 Database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/h2-database/pSi-UJ9H-3k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to h2-database...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/h2-database/12c16c7c-9f1a-4d61-9972-ed4e87418661%40googlegroups.com.

Noel Grandin

unread,
Jul 4, 2019, 2:47:56 PM7/4/19
to h2-da...@googlegroups.com
You can call cancel() on a Statement, but the way that H2 implements cancel() means that only some stages of query processing can be interrupted. So how effective it is, depends on where the query is getting stuck.

Meni Hillel

unread,
Jul 4, 2019, 3:29:42 PM7/4/19
to H2 Google Group
I have no issue if it takes couple of seconds longer. I'm using Hibernate... Need to research if jdbc cancel statesment is exposed... 

On Thu, Jul 4, 2019, 11:47 AM Noel Grandin <noelg...@gmail.com> wrote:
You can call cancel() on a Statement, but the way that H2 implements cancel() means that only some stages of query processing can be interrupted. So how effective it is, depends on where the query is getting stuck.

--
You received this message because you are subscribed to a topic in the Google Groups "H2 Database" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/h2-database/pSi-UJ9H-3k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to h2-database...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages