List of usage examples for java.util.concurrent Executor execute
void execute(Runnable command);
From source file:org.onehippo.cms7.launcher.LoggingPanel.java
private void startPolling() { final TailerListener listener = new TailerListenerAdapter() { @Override// w w w. ja v a 2s.co m public void handle(final String line) { try { loggingDocument.insertString(0, System.lineSeparator(), null); loggingDocument.insertString(0, line, null); } catch (BadLocationException e) { throw new RuntimeException(e); } } }; final File catalinaLogFile = getCatalinaLogFile(); final Executor logFilePollingExecutor = Executors.newSingleThreadExecutor(); logFilePollingExecutor.execute(Tailer.create(catalinaLogFile, listener, 100L)); }
From source file:ufo.remote.calls.benchmark.client.caller.resttemplate.AsyncRestTemplateTester.java
@Override protected void startTest(final TesterResult result) { String url = "http://" + hostname + ":" + port + path; CountDownLatch latch = new CountDownLatch(result.totalCalls); AtomicInteger failures = new AtomicInteger(0); Executor executor = Executors.newFixedThreadPool(10); for (int i = 0; i < result.totalCalls; i++) { executor.execute(new Caller(url, result.message, latch, failures)); }/* ww w.j av a 2 s . com*/ try { latch.await(); } catch (InterruptedException e) { throw new RuntimeException(e); } result.failures = failures.get(); }
From source file:com.athena.meerkat.controller.web.provisioning.log.LogTailerListenerTest.java
@Test public void testHandleString() { LogTailerListener listener = new LogTailerListener(new WebSocketSessionMock()); long delay = 2000; File file = new File("G:\\project\\AthenaMeerkat\\meerkat.log"); Tailer tailer = new Tailer(file, listener, delay); // stupid executor impl. for demo purposes Executor executor = new Executor() { public void execute(Runnable command) { command.run();/* w w w. j a v a 2 s.co m*/ } }; executor.execute(tailer); /* Thread thread = new Thread(tailer); thread.setDaemon(true); thread.start(); try{ Thread.sleep(10000); }catch(Exception e){} */ }
From source file:org.apache.drill.exec.service.ServiceEngine.java
private void submit(Executor p, final String name, final AutoCloseable c) { p.execute(new Runnable() { @Override/*from w ww. jav a2 s . co m*/ public void run() { Stopwatch watch = Stopwatch.createStarted(); try { c.close(); } catch (Exception e) { logger.warn("Failure while closing {}.", name, e); } long elapsed = watch.elapsed(MILLISECONDS); if (elapsed > 500) { logger.info("closed " + name + " in " + elapsed + " ms"); } } }); }
From source file:org.flywaydb.core.FlywayPerformanceMediumTest.java
@Before public void generateLotsOfInstallerScripts() throws IOException { //noinspection ResultOfMethodCallIgnored new File(DIR).mkdirs(); Executor executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2); for (int i = (scriptCount - 500); i < scriptCount; i++) { final int j = i; executor.execute(new Runnable() { @Override/*ww w . ja va 2s. c o m*/ public void run() { try { IOUtils.write("SELECT " + j + " FROM DUAL", new FileOutputStream(DIR + "/V" + j + "__Test.sql")); } catch (IOException e) { e.printStackTrace(); } } }); } }
From source file:org.springframework.context.event.SimpleApplicationEventMulticaster.java
@Override public void multicastEvent(final ApplicationEvent event, @Nullable ResolvableType eventType) { ResolvableType type = (eventType != null ? eventType : resolveDefaultEventType(event)); for (final ApplicationListener<?> listener : getApplicationListeners(event, type)) { Executor executor = getTaskExecutor(); if (executor != null) { executor.execute(() -> invokeListener(listener, event)); } else {/* w w w.j a va 2s. co m*/ invokeListener(listener, event); } } }
From source file:org.springframework.integration.ip.udp.DatagramPacketMulticastSendingHandlerTests.java
@Test public void verifySendMulticast() throws Exception { MulticastSocket socket;//w ww .j av a 2s . co m try { socket = new MulticastSocket(); } catch (Exception e) { return; } final int testPort = socket.getLocalPort(); final String multicastAddress = this.multicastRule.getGroup(); final String payload = "foo"; final CountDownLatch listening = new CountDownLatch(2); final CountDownLatch received = new CountDownLatch(2); Runnable catcher = () -> { try { byte[] buffer = new byte[8]; DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length); MulticastSocket socket1 = new MulticastSocket(testPort); socket1.setInterface(InetAddress.getByName(multicastRule.getNic())); InetAddress group = InetAddress.getByName(multicastAddress); socket1.joinGroup(group); listening.countDown(); LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " waiting for packet"); socket1.receive(receivedPacket); socket1.close(); byte[] src = receivedPacket.getData(); int length = receivedPacket.getLength(); int offset = receivedPacket.getOffset(); byte[] dest = new byte[length]; System.arraycopy(src, offset, dest, 0, length); assertEquals(payload, new String(dest)); LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " received packet"); received.countDown(); } catch (Exception e) { listening.countDown(); e.printStackTrace(); } }; Executor executor = Executors.newFixedThreadPool(2); executor.execute(catcher); executor.execute(catcher); assertTrue(listening.await(10000, TimeUnit.MILLISECONDS)); MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler(multicastAddress, testPort); handler.setBeanFactory(mock(BeanFactory.class)); handler.setLocalAddress(this.multicastRule.getNic()); handler.afterPropertiesSet(); handler.handleMessage(MessageBuilder.withPayload(payload).build()); assertTrue(received.await(10000, TimeUnit.MILLISECONDS)); handler.stop(); socket.close(); }
From source file:org.springframework.integration.ip.udp.DatagramPacketMulticastSendingHandlerTests.java
@Test public void verifySendMulticastWithAcks() throws Exception { MulticastSocket socket;//ww w . j a v a 2s . c o m try { socket = new MulticastSocket(); } catch (Exception e) { return; } final int testPort = socket.getLocalPort(); final AtomicInteger ackPort = new AtomicInteger(); final String multicastAddress = "225.6.7.8"; final String payload = "foobar"; final CountDownLatch listening = new CountDownLatch(2); final CountDownLatch ackListening = new CountDownLatch(1); final CountDownLatch ackSent = new CountDownLatch(2); Runnable catcher = () -> { try { byte[] buffer = new byte[1000]; DatagramPacket receivedPacket = new DatagramPacket(buffer, buffer.length); MulticastSocket socket1 = new MulticastSocket(testPort); socket1.setInterface(InetAddress.getByName(multicastRule.getNic())); socket1.setSoTimeout(8000); InetAddress group = InetAddress.getByName(multicastAddress); socket1.joinGroup(group); listening.countDown(); assertTrue(ackListening.await(10, TimeUnit.SECONDS)); LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " waiting for packet"); socket1.receive(receivedPacket); socket1.close(); byte[] src = receivedPacket.getData(); int length = receivedPacket.getLength(); int offset = receivedPacket.getOffset(); byte[] dest = new byte[6]; System.arraycopy(src, offset + length - 6, dest, 0, 6); assertEquals(payload, new String(dest)); LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " received packet"); DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper(); mapper.setAcknowledge(true); mapper.setLengthCheck(true); Message<byte[]> message = mapper.toMessage(receivedPacket); Object id = message.getHeaders().get(IpHeaders.ACK_ID); byte[] ack = id.toString().getBytes(); DatagramPacket ackPack = new DatagramPacket(ack, ack.length, new InetSocketAddress(multicastRule.getNic(), ackPort.get())); DatagramSocket out = new DatagramSocket(); out.send(ackPack); LogFactory.getLog(getClass()) .debug(Thread.currentThread().getName() + " sent ack to " + ackPack.getSocketAddress()); out.close(); ackSent.countDown(); socket1.close(); } catch (Exception e) { listening.countDown(); e.printStackTrace(); } }; Executor executor = Executors.newFixedThreadPool(2); executor.execute(catcher); executor.execute(catcher); assertTrue(listening.await(10000, TimeUnit.MILLISECONDS)); MulticastSendingMessageHandler handler = new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000); handler.setLocalAddress(this.multicastRule.getNic()); handler.setMinAcksForSuccess(2); handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.start(); waitAckListening(handler); ackPort.set(handler.getAckPort()); ackListening.countDown(); handler.handleMessage(MessageBuilder.withPayload(payload).build()); assertTrue(ackSent.await(10000, TimeUnit.MILLISECONDS)); handler.stop(); socket.close(); }
From source file:org.green.code.async.executor.ThreadPoolTaskExecutor.java
public void execute(Runnable task) { Executor executor = getThreadPoolExecutor(); try {/*w w w . j a v a2 s .c o m*/ executor.execute(task); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
From source file:be.vlaanderen.sesam.monitor.internal.util.ThreadPoolTaskScheduler.java
public void execute(Runnable task) { Executor executor = getScheduledExecutor(); try {/*w w w. ja va 2 s. c o m*/ executor.execute(errorHandlingTask(task, false)); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }