List of usage examples for java.util.concurrent ExecutorService getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:xyz.cloudbans.client.Clients.java
public static Client create(ExecutorService executor, ClientConfig config) { if (executor instanceof ThreadPoolExecutor) return create((ThreadPoolExecutor) executor, config); else//from www.j a va 2 s. c om throw new IllegalArgumentException( "Executor of type " + executor.getClass().getName() + " is not supported."); }
From source file:com.brienwheeler.lib.concurrent.ExecutorsTest.java
@Test public void testFinalize() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { NamedThreadFactory threadFactory = new NamedThreadFactory(THREAD_FACTORY_NAME); ExecutorService executor = Executors.newSingleThreadExecutor(threadFactory); Assert.assertFalse(executor.isShutdown()); Method finalize = executor.getClass().getDeclaredMethod("finalize"); finalize.setAccessible(true);// w w w . jav a 2 s . c o m finalize.invoke(executor); Assert.assertTrue(executor.isShutdown()); }
From source file:org.apache.camel.impl.DefaultExecutorServiceStrategy.java
private void onThreadPoolCreated(ExecutorService executorService, Object source, String threadPoolProfileId) { // add to internal list of thread pools executorServices.add(executorService); String id;//w ww . j av a 2 s. c o m String sourceId = null; String routeId = null; // extract id from source if (source instanceof OptionalIdentifiedDefinition) { id = ((OptionalIdentifiedDefinition) source).idOrCreate(camelContext.getNodeIdFactory()); // and let source be the short name of the pattern sourceId = ((OptionalIdentifiedDefinition) source).getShortName(); } else if (source instanceof String) { id = (String) source; } else if (source != null) { // fallback and use the simple class name with hashcode for the id so its unique for this given source id = source.getClass().getSimpleName() + "(" + ObjectHelper.getIdentityHashCode(source) + ")"; } else { // no source, so fallback and use the simple class name from thread pool and its hashcode identity so its unique id = executorService.getClass().getSimpleName() + "(" + ObjectHelper.getIdentityHashCode(executorService) + ")"; } // id is mandatory ObjectHelper.notEmpty(id, "id for thread pool " + executorService); // extract route id if possible if (source instanceof ProcessorDefinition) { RouteDefinition route = ProcessorDefinitionHelper.getRoute((ProcessorDefinition) source); if (route != null) { routeId = route.idOrCreate(camelContext.getNodeIdFactory()); } } // let lifecycle strategy be notified as well which can let it be managed in JMX as well if (executorService instanceof ThreadPoolExecutor) { ThreadPoolExecutor threadPool = (ThreadPoolExecutor) executorService; for (LifecycleStrategy lifecycle : camelContext.getLifecycleStrategies()) { lifecycle.onThreadPoolAdd(camelContext, threadPool, id, sourceId, routeId, threadPoolProfileId); } } // now call strategy to allow custom logic onNewExecutorService(executorService); }
From source file:password.pwm.util.java.JavaHelper.java
public static boolean closeAndWaitExecutor(final ExecutorService executor, final TimeDuration timeDuration) { if (executor == null) { return true; }/*from w w w . ja v a 2s .co m*/ executor.shutdown(); try { return executor.awaitTermination(timeDuration.getTotalMilliseconds(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { LOGGER.warn("unexpected error shutting down executor service " + executor.getClass().toString() + " error: " + e.getMessage()); } return false; }