File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed 
src/main/java/org/mybatis/spring Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 1616package  org .mybatis .spring ;
1717
1818import  java .sql .SQLException ;
19+ import  java .util .concurrent .locks .ReentrantLock ;
1920import  java .util .function .Supplier ;
2021
2122import  javax .sql .DataSource ;
@@ -41,6 +42,7 @@ public class MyBatisExceptionTranslator implements PersistenceExceptionTranslato
4142
4243  private  final  Supplier <SQLExceptionTranslator > exceptionTranslatorSupplier ;
4344  private  SQLExceptionTranslator  exceptionTranslator ;
45+   private  ReentrantLock  lock  = new  ReentrantLock ();
4446
4547  /** 
4648   * Creates a new {@code PersistenceExceptionTranslator} instance with {@code SQLErrorCodeSQLExceptionTranslator}. 
@@ -104,9 +106,14 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
104106  /** 
105107   * Initializes the internal translator reference. 
106108   */ 
107-   private  synchronized  void  initExceptionTranslator () {
108-     if  (this .exceptionTranslator  == null ) {
109-       this .exceptionTranslator  = exceptionTranslatorSupplier .get ();
109+   private  void  initExceptionTranslator () {
110+     lock .lock ();
111+     try  {
112+       if  (this .exceptionTranslator  == null ) {
113+         this .exceptionTranslator  = exceptionTranslatorSupplier .get ();
114+       }
115+     } finally  {
116+       lock .unlock ();
110117    }
111118  }
112119
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments