6
6
import java .net .URL ;
7
7
import java .util .*;
8
8
import java .util .concurrent .ConcurrentHashMap ;
9
- import java .util .concurrent .atomic .AtomicBoolean ;
10
- import java .util .logging .Level ;
11
9
12
10
import com .microsoft .azure .functions .internal .spi .middleware .Middleware ;
13
11
import com .microsoft .azure .functions .rpc .messages .*;
@@ -35,9 +33,10 @@ public class JavaFunctionBroker {
35
33
private final Map <String , ImmutablePair <String , FunctionDefinition >> methods ;
36
34
private final ClassLoaderProvider classLoaderProvider ;
37
35
private String workerDirectory ;
38
- private final AtomicBoolean oneTimeLogicInitialized = new AtomicBoolean ( false ) ;
36
+ private volatile boolean oneTimeLogicInitialized = false ;
39
37
private volatile InvocationChainFactory invocationChainFactory ;
40
38
private volatile FunctionInstanceInjector functionInstanceInjector ;
39
+ private final Object oneTimeLogicInitializationLock = new Object ();
41
40
42
41
private FunctionInstanceInjector newInstanceInjector () {
43
42
return new FunctionInstanceInjector () {
@@ -63,9 +62,14 @@ public void loadMethod(FunctionMethodDescriptor descriptor, Map<String, BindingI
63
62
}
64
63
65
64
private void initializeOneTimeLogics () {
66
- if (!oneTimeLogicInitialized .getAndSet (true )) {
67
- initializeInvocationChainFactory ();
68
- initializeFunctionInstanceInjector ();
65
+ if (!oneTimeLogicInitialized ) {
66
+ synchronized (oneTimeLogicInitializationLock ) {
67
+ if (!oneTimeLogicInitialized ) {
68
+ initializeInvocationChainFactory ();
69
+ initializeFunctionInstanceInjector ();
70
+ oneTimeLogicInitialized = true ;
71
+ }
72
+ }
69
73
}
70
74
}
71
75
0 commit comments