Package java.util.concurrent

Examples of java.util.concurrent.ScheduledExecutorService


   public void start()
   {
      // start a thread, garbage expired cookie token every [DELAY_TIME]
      final AbstractTokenService service = this;
      ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
      executor.scheduleWithFixedDelay(new Runnable()
      {
         public void run()
         {
            service.cleanExpiredTokens();
         }
View Full Code Here


    executor.setThreadFactory(new ThreadFactoryBuilder()
        .setDaemon(true)
        .setThreadFactory(executor.getThreadFactory())
        .build());

    ScheduledExecutorService service =
        Executors.unconfigurableScheduledExecutorService(executor);

    addDelayedShutdownHook(service, terminationTimeout, timeUnit);

    return service;
View Full Code Here

            if (!(transport.getOOBThreadPool() instanceof ManagedExecutorService)) {
                transport.setOOBThreadPool(new ManagedExecutorService(oobExecutor));
            }
        }
       
        ScheduledExecutorService timerExecutor = transportConfig.getTimerExecutor();
        if (timerExecutor != null) {
         
        }
  }
View Full Code Here

  {
    super.init();
    mountPage("feed", FeedPage.class);
    mountPage("add-content", AddContentPage.class);
   
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
    executor.scheduleAtFixedRate(new TimestamperTask(this), 0, 30, TimeUnit.SECONDS);
  }
View Full Code Here

    private static final int SCHEDULED_THREADS_POOL_SIZE = 30;

    @Override
    protected void configure() {
        // TODO Add instrumentation to ExecutorService and ThreadFactory
        final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE,
                new ThreadFactoryBuilder()
                        .setNameFormat("scheduled-%d")
                        .setDaemon(false)
                        .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LoggerFactory.getLogger("org.graylog2.scheduler.Scheduler")))
                        .build()
        );

        bind(ScheduledExecutorService.class).annotatedWith(Names.named("scheduler")).toInstance(scheduler);

        // TODO Add instrumentation to ExecutorService and ThreadFactory
        final ScheduledExecutorService daemonScheduler = Executors.newScheduledThreadPool(SCHEDULED_THREADS_POOL_SIZE,
                new ThreadFactoryBuilder()
                        .setNameFormat("scheduled-daemon-%d")
                        .setDaemon(true)
                        .setUncaughtExceptionHandler(new Tools.LogUncaughtExceptionHandler(LoggerFactory.getLogger("org.graylog2.scheduler.DaemonScheduler")))
                        .build()
View Full Code Here

                    "Starting [{}] periodical in [{}s], polling every [{}s].",
                    periodical.getClass().getCanonicalName(),
                    periodical.getInitialDelaySeconds(),
                    periodical.getPeriodSeconds());

            ScheduledExecutorService scheduler = periodical.isDaemon() ? this.daemonScheduler : this.scheduler;
            ScheduledFuture<?> future = scheduler.scheduleAtFixedRate(
                    periodical,
                    periodical.getInitialDelaySeconds(),
                    periodical.getPeriodSeconds(),
                    TimeUnit.SECONDS
            );
View Full Code Here

            LOG.warn("Setting counter from {} to 0 because the queue is empty!", counter.get());
            counter.set(0);
            commit();
        }

        final ScheduledExecutorService commitService = commitExecutorService();
        commitService.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                try {
                    commit();
                } catch (Exception e) {
View Full Code Here

                return new HostPort(input);
            }
        }));

        // every so often, we bring back a black-listed server
        ScheduledExecutorService background = Executors.newSingleThreadScheduledExecutor();
        background.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                if (serverBlackList.size() > 0) {
                    serverBlackList.elementSet().remove(serverBlackList.iterator().next());
                }
View Full Code Here

            if (executorService instanceof ScheduledExecutorService) {
                return (ScheduledExecutorService) executorService;
            }
            throw new IllegalArgumentException("ExecutorServiceRef " + definition.getExecutorServiceRef() + " is not an ScheduledExecutorService instance");
        } else if (definition.getExecutorServiceRef() != null) {
            ScheduledExecutorService answer = lookupScheduledExecutorServiceRef(routeContext, name, definition, definition.getExecutorServiceRef());
            if (answer == null) {
                throw new IllegalArgumentException("ExecutorServiceRef " + definition.getExecutorServiceRef() + " not found in registry or as a thread pool profile.");
            }
            return answer;
        } else if (useDefault) {
View Full Code Here

    public void shouldSupportConcurrentlyCreatingNewKeys() throws InterruptedException {
        // note. this test did never actually trigger the race condition so only limited confidence here.
        // this is the best I've come up with so far for actually triggering the conditions this breaks
        int factor = 666;
        int startIndex = EfficientString.nextIndex();
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(20);
        final JsonObject o = new JsonObject();
        // this should create some potential for the race condition to trigger since it rapidly creates the same keys
        int total = 100000;
        for(int i=0;i<total;i++) {
            // make sure we are actually creating new Strings with no overlap with the other tests
            final String str="shouldSupportConcurrentlyCreatingNewKeys-"+ (i/factor);
            executorService.execute(new Runnable() {

                @Override
                public void run() {
                    o.put(str, str); // this should never fail with null key because of the (hopefully) now fixed EfficientString
                    EfficientString e = EfficientString.fromString(str);
                    assertThat(EfficientString.fromString(str), is(e));
                }
            });
        }

        executorService.shutdown();
        executorService.awaitTermination(2, TimeUnit.SECONDS);
        // check greater than so that it won't clash with concurrent executions of other tests in surefire
        assertThat(EfficientString.nextIndex()-startIndex, Matchers.greaterThan(total/factor));
    }
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.