Thread interruption and concurrent close

Dave Cramer davecramer at gmail.com
Mon May 19 09:43:17 UTC 2025


I've always assumed that the driver public API was not intended to be
thread-safe. Yes there are internal threads but externally no.
Dave Cramer


On Sun, 18 May 2025 at 21:47, David Bullock <db at dawnbreaks.net> wrote:

> As a mere spec user, I agree that the doc could be clearer.  Only
> #setNetworkTimeout(Executor) makes mention of an 'administrative thread' in
> connection with #abort(Executer), but #abort(Executor) itself is silent
> about this.   Further, although mention of an 'administrative thread'
> implies that the Connection is visible to multiple threads, a class-level
> doc about the thread-safety of the object along the lines of: "not
> guaranteed to be thread safe, except for #abort(Executor) and
> #setNetworkTimeout(Executor)" would still be helpful.
>
> On Sat, 17 May 2025 at 02:51, Pavel Rappo <pavel.rappo at gmail.com> wrote:
>
>> Okay, so Connection.abort(Executor) is a safe way to initialise the
>> connection closure. Is there any example use of that method available?
>> Separately, JDBC seems to be silent on threading. Those few methods that
>> take Executor seem to have been added relatively recently.
>>
>> On Thu, May 15, 2025 at 4:41 PM Douglas Surber <douglas.surber at oracle.com>
>> wrote:
>>
>>> The intended way to handle this is to call Connection.abort(Executor) on
>>> the offending Connections. This method will mark the Connection as closed
>>> and return quickly. It may also schedule a task to perform any long running
>>> work appropriate to actually shutdown and clean up the Connection and its
>>> resources. Because the Connection may be in use, and thus locks held,
>>> cleaning up the Connection may not take place until the locks are released
>>> perhaps after the socket timeout. The default socket timeout is something
>>> like 15 minutes so this can take a while.
>>>
>>> Douglas Surber
>>>
>>> Connection (Java SE 23 & JDK 23)
>>> <https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/Connection.html#abort(java.util.concurrent.Executor)>
>>> docs.oracle.com
>>> <https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/Connection.html#abort(java.util.concurrent.Executor)>
>>> [image: favicon.ico]
>>> <https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/Connection.html#abort(java.util.concurrent.Executor)>
>>> <https://docs.oracle.com/en/java/javase/23/docs/api/java.sql/java/sql/Connection.html#abort(java.util.concurrent.Executor)>
>>>
>>>
>>> On May 13, 2025, at 11:27 AM, Pavel Rappo <pavel.rappo at gmail.com> wrote:
>>>
>>> Is it specified how JDBC methods should react to thread interruption
>>> and concurrent closure of the connection?
>>>
>>> As a JDBC user, I'm trying to figure out my best course of action in
>>> the following scenario. A statement has been executing for a while
>>> when the application shutdown hook starts. The hook should quickly
>>> shut down everything and return.
>>>
>>> -Pavel
>>>
>>>
>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdbc-spec-discuss/attachments/20250519/f011f68b/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: favicon.ico
Type: application/octet-stream
Size: 10134 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/jdbc-spec-discuss/attachments/20250519/f011f68b/favicon-0001.ico>


More information about the jdbc-spec-discuss mailing list