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

后端 未结 9 1119
鱼传尺愫
鱼传尺愫 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-13 13:13

    What we did was

    @Override
    public void run() {
      try {
        // ...
      } finally {
        resource.close();
      }
    }
    

    Basically just always (possibly open and then) close it for all paths through the thread. In case it helps anybody out there :)

提交回复
热议问题