@@ -75,18 +75,20 @@ public void initXaTwoPhaseTimeoutChecker() {
7575 xaTwoPhaseTimeoutChecker .scheduleAtFixedRate (() -> {
7676 for (Map .Entry <String , Resource > entry : dataSourceCache .entrySet ()) {
7777 BaseDataSourceResource resource = (BaseDataSourceResource )entry .getValue ();
78- if (resource instanceof DataSourceProxyXA ) {
79- Map <String , ConnectionProxyXA > keeper = resource .getKeeper ();
80- for (Map .Entry <String , ConnectionProxyXA > connectionEntry : keeper .entrySet ()) {
81- ConnectionProxyXA connection = connectionEntry .getValue ();
82- long now = System .currentTimeMillis ();
83- synchronized (connection ) {
84- if (connection .getPrepareTime () != null
85- && now - connection .getPrepareTime () > TWO_PHASE_HOLD_TIMEOUT ) {
86- try {
87- connection .closeForce ();
88- } catch (SQLException e ) {
89- LOGGER .info ("Force close the xa physical connection fail" , e );
78+ if (resource .isShouldBeHeld ()) {
79+ if (resource instanceof DataSourceProxyXA ) {
80+ Map <String , ConnectionProxyXA > keeper = resource .getKeeper ();
81+ for (Map .Entry <String , ConnectionProxyXA > connectionEntry : keeper .entrySet ()) {
82+ ConnectionProxyXA connection = connectionEntry .getValue ();
83+ long now = System .currentTimeMillis ();
84+ synchronized (connection ) {
85+ if (connection .getPrepareTime () != null
86+ && now - connection .getPrepareTime () > TWO_PHASE_HOLD_TIMEOUT ) {
87+ try {
88+ connection .closeForce ();
89+ } catch (SQLException e ) {
90+ LOGGER .info ("Force close the xa physical connection fail" , e );
91+ }
9092 }
9193 }
9294 }
0 commit comments