| 157 | private static ExecutorService clientExecutor; |
| 158 | |
| 159 | private static synchronized ExecutorService getExecutor() { |
| 160 | if (clientExecutor == null) { |
| 161 | clientExecutor = new ForkJoinPool( |
| 162 | Runtime.getRuntime().availableProcessors(), |
| 163 | new ForkJoinWorkerThreadFactory() { |
| 164 | final AtomicInteger num = new AtomicInteger(); |
| 165 | @Override |
| 166 | public ForkJoinWorkerThread newThread(ForkJoinPool pool) { |
| 167 | ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool); |
| 168 | thread.setDaemon(true); |
| 169 | thread.setName("grpc-client-app-" + "-" + num.getAndIncrement()); |
| 170 | return thread; |
| 171 | } |
| 172 | }, UncaughtExceptionHandlers.systemExit(), true /* async */); |
| 173 | } |
| 174 | return clientExecutor; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Create a {@link ManagedChannel} for the given parameters. |