Package java.util.concurrent

Examples of java.util.concurrent.ScheduledExecutorService


            answer.setAggregationRepository(repository);
        }

        // this EIP supports using a shared timeout checker thread pool or fallback to create a new thread pool
        boolean shutdownTimeoutThreadPool = false;
        ScheduledExecutorService timeoutThreadPool = timeoutCheckerExecutorService;
        if (timeoutThreadPool == null && timeoutCheckerExecutorServiceRef != null) {
            // lookup existing thread pool
            timeoutThreadPool = routeContext.getCamelContext().getRegistry().lookup(timeoutCheckerExecutorServiceRef, ScheduledExecutorService.class);
            if (timeoutThreadPool == null) {
                // then create a thread pool assuming the ref is a thread pool profile id
View Full Code Here


public class TimerListenerManagerTest extends TestCase {

    private final MyTask task = new MyTask();

    public void testTimerListenerManager() throws Exception {
        ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
        TimerListenerManager manager = new TimerListenerManager();
        manager.setExecutorService(executor);
        manager.addTimerListener(task);
        manager.start();

        assertTrue("Should be invoked", task.await());

        manager.stop();
        manager.removeTimerListener(task);
        executor.shutdown();
    }
View Full Code Here

        ObjectHelper.notNull(camelContext, "CamelContext");

        boolean enabled = camelContext.getManagementStrategy().getStatisticsLevel() != ManagementStatisticsLevel.Off;
        if (enabled) {
            LOG.info("StatisticsLevel at {} so enabling load performance statistics", camelContext.getManagementStrategy().getStatisticsLevel());
            ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "ManagementLoadTask");
            timerListenerManager.setExecutorService(executorService);
            // must use 1 sec interval as the load statistics is based on 1 sec calculations
            timerListenerManager.setInterval(1000);
            ServiceHelper.startService(timerListenerManager);
        }
View Full Code Here

public class LoadTimerTest extends TestCase {

    private static final int SAMPLES = 3;

    public void testTimer() throws Exception {
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);

        TimerListenerManager myTimer = new TimerListenerManager();
        myTimer.setExecutorService(executorService);
        myTimer.start();

        TestLoadAware test = new TestLoadAware();
        myTimer.addTimerListener(test);
        try {
            Thread.sleep(1000 * (SAMPLES + 1));
            assertTrue(test.counter >= SAMPLES);
            assertFalse(Double.isNaN(test.load.getLoad1()));
            assertTrue(test.load.getLoad1() > 0.0d);
            assertTrue(test.load.getLoad1() < SAMPLES);
        } finally {
            myTimer.removeTimerListener(test);
        }

        myTimer.stop();
        executorService.shutdown();
    }
View Full Code Here

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                // share 8 threads among the 20 routes
                ScheduledExecutorService threadPool = context.getExecutorServiceManager().newScheduledThreadPool(this, "MyThreadPool", 8);
                for (int i = 0; i < NUM_AGGREGATORS; ++i) {
                    from("direct:start" + i)
                        // aggregate timeout after 3th seconds
                        .aggregate(header("id"), new UseLatestAggregationStrategy()).completionTimeout(3000).timeoutCheckerExecutorService(threadPool)
                        .to("mock:result" + i);
View Full Code Here

        assertEquals("Should not be any throttled messages left, found: " + throttledMessages, (Integer) 0, throttledMessages);
    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        final ScheduledExecutorService badService = new ScheduledThreadPoolExecutor(1) {
            @Override
            public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) {
                throw new RejectedExecutionException();
            }
        };
View Full Code Here

        // wake up threads waiting on this instance's monitor (e.g. workspace janitor)
        notifyAll();

        // Shut down the executor service
        ScheduledExecutorService executor = context.getExecutor();
        executor.shutdown();
        try {
            // Wait for all remaining background threads to terminate
            if (!executor.awaitTermination(10, TimeUnit.SECONDS)) {
                log.warn("Attempting to forcibly shutdown runaway threads");
                executor.shutdownNow();
            }
        } catch (InterruptedException e) {
            log.warn("Interrupted while waiting for background threads", e);
        }
View Full Code Here

        t.start();

        final int FACTS_PER_POLL = 1000;
        final int POLL_INTERVAL = 500;

        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
        executor.scheduleAtFixedRate(
                new Runnable() {

                    public void run() {
                        for ( int j = 0; j < FACTS_PER_POLL; j++ ) {
                            ksession.insert( new MyFact() );
                        }
                    }
                },
                0,
                POLL_INTERVAL,
                TimeUnit.MILLISECONDS );


        Thread.sleep( 10200 );

        executor.shutdownNow();
        ksession.halt();
        t.join();

        if (t.getError() != null) {
            fail(t.getError().getMessage());
View Full Code Here

    final Set<Long> unclassified = new HashSet<Long>();
    for (long i = 0; i < 20; i++) {
      unclassified.add(i);
    }

    final ScheduledExecutorService serviceScheduler = Executors.newSingleThreadScheduledExecutor();
    final Client restLiClient = new ClientImpl(serviceScheduler);

    final int numCores = Runtime.getRuntime().availableProcessors();
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(numCores + 1);
    final Engine engine = new EngineBuilder()
        .setTaskExecutor(scheduler)
        .setTimerScheduler(scheduler)
        .build();

    final ClassifierPlanFactory classifier = new ClassifierPlanFactory(restLiClient);
    try
    {
      final Task<Map<Long, Classification>> classifications = classifier.classify(viewerId, unclassified);
      engine.run(classifications);
      classifications.await();
      System.out.println(classifications.get());

      ExampleUtil.printTracingResults(classifications);
    }
    finally
    {
      serviceScheduler.shutdownNow();
      engine.shutdown();
      scheduler.shutdownNow();
    }
  }
View Full Code Here

  public void runExample() throws Exception
  {
    _serviceScheduler = Executors.newScheduledThreadPool(2);
    final int numCores = Runtime.getRuntime().availableProcessors();
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(numCores + 1);
    final Engine engine = new EngineBuilder()
        .setTaskExecutor(scheduler)
        .setTimerScheduler(scheduler)
        .build();
    try
    {
      doRunExample(engine);
    }
    finally
    {
      engine.shutdown();
      scheduler.shutdownNow();
      _serviceScheduler.shutdown();
      _serviceScheduler = null;
    }
  }
View Full Code Here

TOP

Related Classes of java.util.concurrent.ScheduledExecutorService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.