/** {@inheritDoc} */ @Override protected GridConfiguration getConfiguration(String gridName) throws Exception { GridConfiguration c = super.getConfiguration(gridName); c.setLocalHost(HOST); assert c.getClientConnectionConfiguration() == null; GridClientConnectionConfiguration clientCfg = new GridClientConnectionConfiguration(); clientCfg.setRestTcpPort(REST_TCP_PORT_BASE); GridSslContextFactory sslCtxFactory = sslContextFactory(); if (sslCtxFactory != null) { clientCfg.setRestTcpSslEnabled(true); clientCfg.setRestTcpSslContextFactory(sslCtxFactory); } c.setClientConnectionConfiguration(clientCfg); GridTcpDiscoverySpi disco = new GridTcpDiscoverySpi(); disco.setIpFinder(IP_FINDER); c.setDiscoverySpi(disco); TestCommunicationSpi spi = new TestCommunicationSpi(); spi.setLocalPort(GridTestUtils.getNextCommPort(getClass())); c.setCommunicationSpi(spi); c.setCacheConfiguration( cacheConfiguration(null), cacheConfiguration(PARTITIONED_CACHE_NAME), cacheConfiguration(REPLICATED_CACHE_NAME), cacheConfiguration(REPLICATED_ASYNC_CACHE_NAME)); ThreadPoolExecutor exec = new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>()); exec.prestartAllCoreThreads(); c.setExecutorService(exec); c.setExecutorServiceShutdown(true); ThreadPoolExecutor sysExec = new ThreadPoolExecutor(40, 40, 0, MILLISECONDS, new LinkedBlockingQueue<Runnable>()); sysExec.prestartAllCoreThreads(); c.setSystemExecutorService(sysExec); c.setSystemExecutorServiceShutdown(true); return c; }
static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print) throws Exception { ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads + 1, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, q); CountDownLatch done = new CountDownLatch(iters); remaining.set(nThreads - 1); pool.prestartAllCoreThreads(); Task t = new Task(pool, done); long start = System.nanoTime(); pool.execute(t); done.await(); long time = System.nanoTime() - start; if (print) System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task"); q.clear(); Thread.sleep(100); pool.shutdown(); Thread.sleep(100); pool.shutdownNow(); }
public void run() { done.countDown(); remaining.incrementAndGet(); int n; while (!Thread.interrupted() && (n = remaining.get()) > 0 && done.getCount() > 0) { if (remaining.compareAndSet(n, n - 1)) { try { pool.execute(this); } catch (RuntimeException ex) { System.out.print("*"); while (done.getCount() > 0) done.countDown(); return; } } } }