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 16
16
package org .mybatis .spring ;
17
17
18
18
import java .sql .SQLException ;
19
+ import java .util .concurrent .locks .ReentrantLock ;
19
20
import java .util .function .Supplier ;
20
21
21
22
import javax .sql .DataSource ;
@@ -41,6 +42,7 @@ public class MyBatisExceptionTranslator implements PersistenceExceptionTranslato
41
42
42
43
private final Supplier <SQLExceptionTranslator > exceptionTranslatorSupplier ;
43
44
private SQLExceptionTranslator exceptionTranslator ;
45
+ private ReentrantLock lock = new ReentrantLock ();
44
46
45
47
/**
46
48
* Creates a new {@code PersistenceExceptionTranslator} instance with {@code SQLErrorCodeSQLExceptionTranslator}.
@@ -104,9 +106,14 @@ public DataAccessException translateExceptionIfPossible(RuntimeException e) {
104
106
/**
105
107
* Initializes the internal translator reference.
106
108
*/
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 ();
110
117
}
111
118
}
112
119
You can’t perform that action at this time.
0 commit comments