17
17
*
18
18
*/
19
19
20
- import io .invertase .firebase .common .ReactNativeFirebaseJSON ;
21
-
22
20
import java .util .HashMap ;
23
21
import java .util .Map ;
24
22
import java .util .Set ;
@@ -36,7 +34,7 @@ public class TaskExecutorService {
36
34
private final String name ;
37
35
private final int maximumPoolSize ;
38
36
private final int keepAliveSeconds ;
39
- private static Map <String , ExecutorService > executors = new HashMap <>();
37
+ private static final Map <String , ExecutorService > executors = new HashMap <>();
40
38
41
39
TaskExecutorService (String name ) {
42
40
this .name = name ;
@@ -73,27 +71,25 @@ public ExecutorService getExecutor(boolean isTransactional, String identifier) {
73
71
}
74
72
75
73
private ExecutorService getNewExecutor (boolean isTransactional ) {
76
- if (isTransactional == true ) {
74
+ if (isTransactional ) {
77
75
return Executors .newSingleThreadExecutor ();
78
76
} else {
79
- ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (0 , maximumPoolSize , keepAliveSeconds , TimeUnit .SECONDS , new SynchronousQueue <Runnable >());
77
+ ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor (0 , maximumPoolSize , keepAliveSeconds , TimeUnit .SECONDS , new SynchronousQueue <>());
80
78
threadPoolExecutor .setRejectedExecutionHandler (executeInFallback );
81
79
return threadPoolExecutor ;
82
80
}
83
81
}
84
82
85
- private RejectedExecutionHandler executeInFallback = new RejectedExecutionHandler () {
86
- public void rejectedExecution (Runnable r , ThreadPoolExecutor executor ) {
87
- if (executor .isShutdown () || executor .isTerminated () || executor .isTerminating ()) {
88
- return ;
89
- }
90
- ExecutorService fallbackExecutor = getTransactionalExecutor ();
91
- fallbackExecutor .execute (r );
92
- };
83
+ private final RejectedExecutionHandler executeInFallback = (r , executor ) -> {
84
+ if (executor .isShutdown () || executor .isTerminated () || executor .isTerminating ()) {
85
+ return ;
86
+ }
87
+ ExecutorService fallbackExecutor = getTransactionalExecutor ();
88
+ fallbackExecutor .execute (r );
93
89
};
94
90
95
91
public String getExecutorName (boolean isTransactional , String identifier ) {
96
- if (isTransactional == true ) {
92
+ if (isTransactional ) {
97
93
return name + "TransactionalExecutor" + identifier ;
98
94
}
99
95
return name + "Executor" + identifier ;
@@ -102,10 +98,10 @@ public String getExecutorName(boolean isTransactional, String identifier) {
102
98
public void shutdown () {
103
99
Set <String > existingExecutorNames = executors .keySet ();
104
100
for (String executorName : existingExecutorNames ) {
105
- if (executorName .startsWith (name ) == false ) {
101
+ if (! executorName .startsWith (name )) {
106
102
existingExecutorNames .remove (executorName );
107
103
} else {
108
- removeExecutor (executorName );
104
+ removeExecutor (executorName );
109
105
}
110
106
}
111
107
}
0 commit comments