List of usage examples for java.util.concurrent Executors newScheduledThreadPool
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize)
From source file:com.oltpbenchmark.benchmarks.smallworldbank.SWBankWorker.java
@SuppressWarnings("unchecked") public SWBankWorker(BenchmarkModule benchmarkModule, int id) { super(benchmarkModule, id); exservice = Executors.newScheduledThreadPool(3); rdg = new RandomDataGenerator(new JDKRandomGenerator(id)); // TODO: Get Dataset statistics: int noWorkers = benchmarkModule.getWorkloadConfiguration().getTerminals(); tdp = benchmarkModule.getWorkloadConfiguration().getXmlConfig().getDouble("tdp"); mddelay = benchmarkModule.getWorkloadConfiguration().getXmlConfig().getInt("mddelay"); try {//from www .j a v a 2s.c om long _custIdMax = SWBankUtil.getCustIdMax(this.conn); long _acctIdMax = SWBankUtil.getAcctIdMax(this.conn); long custRange = _custIdMax / noWorkers; long acctRange = _acctIdMax / noWorkers; custIdMin = (id * custRange); custIdMax = custIdMin + custRange; acctIdMin = (id * acctRange); acctIdMax = acctIdMin + acctRange; LOG.info(String.format( "workerId=%d, custIdMin=%d, custIdMax=%d, custRange=%d, " + "acctIdMin=%d, acctIdMax=%d, acctRange=%d, tdp = %f ", id, custIdMin, custIdMax, custRange, acctIdMin, acctIdMax, acctRange, tdp)); } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } // parse specific properties of transaction types }
From source file:org.opendaylight.groupbasedpolicy.renderer.opflex.PolicyManagerTest.java
@Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); int numCPU = Runtime.getRuntime().availableProcessors(); executor = Executors.newScheduledThreadPool(numCPU * 2); dummyEndpoint = new JsonRpcEndpoint(null, null, null, null, new RpcMessageMap(), null); when(mockResolver.registerListener(Matchers.<PolicyListener>any())).thenReturn(mockScope); policyManager = new PolicyManager(mockResolver, mockConnService, executor, mockOpflexLib); }
From source file:com.starit.diamond.server.service.TimerTaskService.java
private void initWithDB(List<ConfigInfo> configInfos) { this.scheduledExecutorService = Executors.newScheduledThreadPool(10); DumpConfigInfoTask configInfoTask = new DumpConfigInfoTask(this, configInfos); configInfoTask.run();/*from w w w . j av a 2 s . co m*/ this.scheduledExecutorService.scheduleAtFixedRate(configInfoTask, SystemConfig.getDumpConfigInterval(), SystemConfig.getDumpConfigInterval(), TimeUnit.SECONDS); }
From source file:org.openoverlayrouter.root.OORService.java
public synchronized void run() { scheduler = Executors.newScheduledThreadPool(1); Runnable dnsCheck = new Runnable() { public void run() { String psOutput = runTask("/system/bin/ps", "", false); isRunning = psOutput.matches("(?s)(.*)[RS]\\s[a-zA-Z0-9\\/\\.\\-]*liboor\\.so(.*)"); if (isRunning && oor_dns != null) { String dns[] = get_dns_servers(); if (!dns[0].equals(oor_dns[0]) || !dns[1].equals(oor_dns[1])) { system_dns = get_dns_servers(); set_dns_servers(oor_dns); }/*from w w w. j av a2 s . c o m*/ } if (isRunning == false) { onDestroy(); } } }; scheduledFuture = scheduler.scheduleAtFixedRate(dnsCheck, 0, 1, TimeUnit.SECONDS); }
From source file:org.lispmob.root.LISPmobService.java
public synchronized void run() { scheduler = Executors.newScheduledThreadPool(1); Runnable dnsCheck = new Runnable() { public void run() { String psOutput = runTask("/system/bin/ps", "", false); isRunning = psOutput.matches("(?s)(.*)[RS]\\s[a-zA-Z0-9\\/\\.\\-]*liblispd\\.so(.*)"); if (isRunning && lispmob_dns != null) { String dns[] = get_dns_servers(); if (!dns[0].equals(lispmob_dns[0]) || !dns[1].equals(lispmob_dns[1])) { system_dns = get_dns_servers(); set_dns_servers(lispmob_dns); }//from w w w . j av a 2 s. c o m } if (isRunning == false) { onDestroy(); } } }; scheduledFuture = scheduler.scheduleAtFixedRate(dnsCheck, 0, 1, TimeUnit.SECONDS); }
From source file:org.openoverlayrouter.noroot.OORService.java
public synchronized void run() { scheduler = Executors.newScheduledThreadPool(1); Runnable dnsCheck = new Runnable() { public void run() { String psOutput = shell.run("/system/bin/ps | grep liboorexec.so"); isRunning = psOutput.matches("(?s)(.*)[RS]\\s[a-zA-Z0-9\\/\\.\\-]*liboorexec\\.so(.*)"); isRunning = true;// w w w . ja v a2 s .co m if (oor_dns != null) { String dns[] = get_dns_servers(); if ((dns[0] != null && !oor_dns.contains(dns[0])) || (dns[1] != null && !oor_dns.contains(dns[1]))) { system_dns = get_dns_servers(); set_dns_servers(oor_dns.toArray(new String[0])); } } if (isRunning == false) { onDestroy(); } } }; scheduledFuture = scheduler.scheduleAtFixedRate(dnsCheck, 0, 1, TimeUnit.SECONDS); }
From source file:com.linkedin.restli.server.RestliServlet.java
private AbstractR2Servlet buildR2ServletFromServletParams(ServletConfig servletConfig) { ResourceFactory resourceFactory = new PrototypeResourceFactory(); RestLiConfig config = new RestLiConfig(); config.setResourcePackageNamesSet(getResourcePackageSet(servletConfig)); final ScheduledExecutorService scheduler = Executors .newScheduledThreadPool(getParseqThreadPoolSize(servletConfig)); Engine engine = new EngineBuilder().setTaskExecutor(scheduler).setTimerScheduler(scheduler).build(); DelegatingTransportDispatcher dispatcher = new DelegatingTransportDispatcher( new RestLiServer(config, resourceFactory, engine)); boolean useAsync = getUseAsync(servletConfig); long asyncTimeOut = getAsyncTimeout(servletConfig); if (useAsync && servletConfig.getServletContext().getMajorVersion() < 3) { throw new IllegalArgumentException( "This servlet is configured with useAsync=true, but the current servlet " + "context does not support the required Servlet API 3.0."); }/* w w w . j a va2 s . c o m*/ if (!useAsync) { log.info( "Initializing Rest.li with a thread based request handling. Set useAsync=true on a Servlet API 3.0 container to enable Rest.li's async servlet."); return new RAPServlet(dispatcher); } else { log.info("Initializing Rest.li with an async request handling enabled."); return new AsyncR2Servlet(dispatcher, asyncTimeOut); } }
From source file:cherry.foundation.mail.SendMailBatchTest.java
@Test public void testInterrupt() throws Exception { final File shutdownTrigger = new File("./shutdownTrigger.txt"); shutdownTrigger.deleteOnExit();/*from w w w .ja va 2 s . com*/ Callable<Boolean> callable = new Callable<Boolean>() { @Override public Boolean call() { try (FileOutputStream os = new FileOutputStream(shutdownTrigger)) { return true; } catch (IOException ex) { return false; } } }; ScheduledExecutorService service = Executors.newScheduledThreadPool(1); ScheduledFuture<Boolean> future = service.schedule(callable, 5L, TimeUnit.SECONDS); final Thread currentThread = Thread.currentThread(); ScheduledFuture<Boolean> interrupt = service.schedule(new Callable<Boolean>() { @Override public Boolean call() { currentThread.interrupt(); return true; } }, 2L, TimeUnit.SECONDS); SendMailBatch batch = create(1000L, shutdownTrigger, false); ExitStatus status = batch.execute(); assertEquals(ExitStatus.NORMAL, status); assertTrue(future.get().booleanValue()); assertTrue(interrupt.get().booleanValue()); assertFalse(shutdownTrigger.exists()); verify(bizDateTime, atLeastOnce()).now(); verify(mailSendHandler, atLeastOnce()).listMessage((LocalDateTime) eq(null)); verify(mailSendHandler, atLeastOnce()).sendMessage(eq(1L)); verify(mailSendHandler, atLeastOnce()).sendMessage(eq(2L)); verify(mailSendHandler, atLeastOnce()).sendMessage(eq(3L)); }
From source file:au.com.jwatmuff.genericp2p.rmi.RMIPeerManager.java
public void start() { log.debug("Obtained local ID: " + this.getUUID()); registerService(AnnounceService.class, this); registerService(IdentifyService.class, this); registerService(LookupService.class, this); fastPeerCheckExecutor = Executors.newScheduledThreadPool(2); slowPeerCheckExecutor = Executors.newScheduledThreadPool(4); fastPeerCheckExecutor.scheduleAtFixedRate(new Runnable() { @Override/* w w w . j a va 2 s . c om*/ public void run() { for (ManagedPeer peer : getManagedPeers()) { log.debug("FAST CHECK CHECKING: " + peer); checkPeer(peer); } } }, 30, 30, TimeUnit.SECONDS); slowPeerCheckExecutor.scheduleAtFixedRate(new Runnable() { @Override public void run() { addSelf(); for (InetSocketAddress address : getAddresses()) { log.debug("SLOW CHECK CHECKING: " + address); checkAddress(address); } } }, 30, 30, TimeUnit.SECONDS); addSelf(); log.debug("Completed RMIPeerManager startup"); }
From source file:com.nts.alphamale.handler.ExecutorHandler.java
public void executePeriodically(Runnable rt, long period) { scheduledExecutor = Executors.newScheduledThreadPool(1); scheduledExecutor.scheduleAtFixedRate(rt, 3 * 1000, period, TimeUnit.MILLISECONDS); }