In a multithreaded environment, auto increment / decrement may lead to thread safety problems, which may lead to some code never executing

if (queryStack.get() == 0 && ms.isFlushCacheRequired()) {
      clearLocalCache();
}
if (queryStack.get() == 0) {
      for (DeferredLoad deferredLoad : deferredLoads) {
        deferredLoad.load();
      }
      // issue #601
      deferredLoads.clear();
      if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
        // issue #482
        clearLocalCache();
      }
}

Comment From: harawata

Executor is not thread safe by design. If you are experiencing a problem you described, you are misusing something, probably. Do you have a repro?

Comment From: viviel

Executor is not thread safe by design. If you are experiencing a problem you described, you are misusing something, probably. Do you have a repro?

That may be because I misunderstood. Let me describe my understanding: The lifecycle of sqlsession is bound to mapper, while the lifecycle of executor is bound to sqlsession. If multiple threads execute the same mapper object, will it indirectly lead to thread safety problems of executor? Or is the process I described wrong?

Comment From: viviel

Sorry, I didn't read the source code of spring-mybatis. Here, SQL session is bound to thread, so there is no thread safety problem. I'll close this pr