How to force a Java thread to close a thread-local database connection

后端 未结 9 1171
鱼传尺愫
鱼传尺愫 2021-02-13 12:41

When Using a thread-local database connection, closure of the connection is required when the thread exists.

This I can only do if I can override the run() method of the

9条回答
  •  忘掉有多难
    2021-02-13 13:21

    Override the get() method in ThreaedLocal so that it sets a List property on the subclass. This property can easily be queried to determine if the get() method had been called for a particular thread. You could then access the ThreadLocal to clean it up in that case.

    Updated in response to comment

提交回复
热议问题