Package java.util.concurrent

Examples of java.util.concurrent.ScheduledExecutorService.schedule()


    @Test
    public void testSingleScheduling() throws InterruptedException, ExecutionException, TimeoutException {
        SignallingRunnable runner = new SignallingRunnable("testSingleScheduling");
        ScheduledExecutorService executor = createScheduledThreadPoolExecutor();
        ScheduledFuture<?> future = executor.schedule(runner, 25L, TimeUnit.MILLISECONDS);
        assertLastExecutionOperation(runner);
        assertCurrentThreadExecution();

        Object result = future.get(5L, TimeUnit.SECONDS);
        assertNull("Unexpected future execution result", result);
View Full Code Here


    long chaosMonkeyDelay = conf.getLong(String.format("%s.%s", TEST_NAME, CHAOS_MONKEY_DELAY_KEY)
      , DEFAUL_CHAOS_MONKEY_DELAY);
    ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
    LOG.info(String.format("ChaosMonkey delay is : %d seconds. Will start %s " +
        "ChaosMonkey after delay", chaosMonkeyDelay / 1000, monkeyToUse));
    ScheduledFuture<?> result = executorService.schedule(new Runnable() {
      @Override
      public void run() {
        try {
          LOG.info("Starting ChaosMonkey");
          monkey.start();
View Full Code Here

            monitor.startMonitoring(scheduler);
        final ScheduledFuture<?> printTask =
            monitor.printMonitoring(scheduler);

        // Run the tasks for 2 minutes
        scheduler.schedule(
            new Runnable() {
                public void run() {
                    monitorTask.cancel(true);
                    printTask.cancel(true);
                }
View Full Code Here

      final StubDataSource stubDataSource = ds.unwrap(StubDataSource.class);
      stubDataSource.setThrowException(new SQLException("Connection refused"));

      ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
      scheduler.schedule(new Runnable() {
         public void run()
         {
            stubDataSource.setThrowException(null);
         }
      }, 300, TimeUnit.MILLISECONDS);
View Full Code Here

      final Connection connection2 = ds.getConnection();
      Assert.assertNotNull(connection1);
      Assert.assertNotNull(connection2);

      ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
      scheduler.schedule(new Runnable() {
         public void run()
         {
            try {
               connection1.close();
            }
View Full Code Here

      final Connection connection1 = ds.getConnection();

      long start = System.currentTimeMillis();

      ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
      scheduler.schedule(new Runnable() {
         public void run()
         {
            try {
               connection1.close();
            }
View Full Code Here

    public void stopExeriment() {
        if (runningExperiment != null && !runningExperiment.isDone()) {
            logger.info("Sending cancel request to solver.");
            currentExperiment.getSolver().addSystemStopCondition(new UserInterruptStopCondition());
            ScheduledExecutorService service = Executors.newScheduledThreadPool(1);
            service.schedule(new Callable<Void>() {

                public Void call() throws Exception {
                    if(!runningExperiment.isDone()) {
                        runningExperiment.cancel(true);
                        logger.info("Experiment forcefully interrupted.");
View Full Code Here

            final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
            if(period > 0) {
                scheduler.scheduleAtFixedRate(runnable, start, period, TimeUnit.MILLISECONDS);
            } else {
                scheduler.schedule(runnable, start, TimeUnit.MILLISECONDS);
            }

            schedulers.add(scheduler);
        } catch (Exception ex) {
            logger.error("Error in maintenance task", ex);
View Full Code Here

        final ScheduledExecutorService executor = Executors.newScheduledThreadPool(3);
        final Server server = http.build(environment);
       
        ((AbstractNetworkConnector)server.getConnectors()[0]).setPort(0);

        ScheduledFuture<Void> cleanup = executor.schedule(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                if (!server.isStopped()) {
                    server.stop();
                }
View Full Code Here

          stat = BSStat.ERROR;
        } else {
          stat = BSStat.SUCCESS;
        }

        scheduler.schedule(new BSStatusCollector(), 0, TimeUnit.SECONDS);
        long startTime = System.currentTimeMillis();
        while (true) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Waiting for hosts status to be updated");
          }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.