H2 supports a query timeout setting. You can set this in the database URL as follows: jdbc:h2:~/db/test;query_timeout=10000
. (Maybe this is not the right approach for you, but it might be for others that read this question.)
You can also cancel a query running in another connection (session) using the cancel_session
function. But for this you need to enable the multi-threaded mode, which is currently not recommended for production use (it is still experimental in version 1.3.175).