Package java.util.concurrent

Examples of java.util.concurrent.ScheduledFuture


            // we use scheduleWithFixedDelay to prevent queue-up of tasks when
            // polling takes longer than the specified frequency, e.g. when the
            // polled database or network is slow or returns large amounts of
            // data.
            PollingReceiverWorker pollingReceiverWorker = this.createWork();
            ScheduledFuture schedule = connector.getScheduler().scheduleWithFixedDelay(
                    new PollingReceiverWorkerSchedule(pollingReceiverWorker), DEFAULT_STARTUP_DELAY,
                    this.getFrequency(), this.getTimeUnit());
            schedules.put(schedule, pollingReceiverWorker);

            if (logger.isDebugEnabled())
View Full Code Here


        synchronized (schedules)
        {
            // cancel our schedules gently: do not interrupt when polling is in progress
            for (Iterator<ScheduledFuture> i = schedules.keySet().iterator(); i.hasNext();)
            {
                ScheduledFuture schedule = i.next();
                schedule.cancel(false);
                // Wait until in-progress PollingRecevierWorker completes.
                int shutdownTimeout = connector.getMuleContext().getConfiguration().getShutdownTimeout();
                PollingReceiverWorker worker = schedules.get(schedule);
                for (int elapsed = 0; worker.isRunning() && elapsed < shutdownTimeout; elapsed += 50)
                {
View Full Code Here

            new MergedRemoteIndexesTaskRequest( indexMergerRequest, indexMerger );

        logger.info( "schedule merge remote index for group {} with cron {}", repositoryGroup.getId(),
                     repositoryGroup.getCronExpression() );

        ScheduledFuture scheduledFuture =
            taskScheduler.schedule( new MergedRemoteIndexesTask( taskRequest ), cronTrigger );
        scheduledFutureMap.put( repositoryGroup.getId(), scheduledFuture );
    }
View Full Code Here

    }

    @Override
    public void unschedule( RepositoryGroup repositoryGroup )
    {
        ScheduledFuture scheduledFuture = scheduledFutureMap.remove( repositoryGroup.getId() );
        if ( scheduledFuture != null )
        {
            scheduledFuture.cancel( true );
        }
    }
View Full Code Here

      return this.currentFuture.isDone();
    }
  }

  public Object get() throws InterruptedException, ExecutionException {
    ScheduledFuture curr;
    synchronized (this.triggerContextMonitor) {
      curr = this.currentFuture;
    }
    return curr.get();
  }
View Full Code Here

    }
    return curr.get(timeout, unit);
  }

  public long getDelay(TimeUnit unit) {
    ScheduledFuture curr;
    synchronized (this.triggerContextMonitor) {
      curr = this.currentFuture;
    }
    return curr.getDelay(unit);
  }
View Full Code Here

            this.event = event;
        }

        public void run()
        {
            ScheduledFuture future = null;
            try
            {
                future = scheduledExecutor.schedule(new Runnable()
                {
                    public void run()
                    {
                        loggers.log(listener.reference, LogService.LOG_WARNING, "Listener timeout, will be blacklisted");
                        LOGGER.log(Level.WARNING, "Listener timeout, will be blacklisted");

                        remove(listener);
                    }
                }, timeout, timeUnit);

                listener.handleEvent(event);
            }
            catch (RejectedExecutionException ree)
            {
                loggers.log(listener.reference, LogService.LOG_WARNING, "Unable to schedule timeout for listener call, call skipped", ree);
                LOGGER.log(Level.WARNING, "Unable to schedule timeout for listener call, call skipped", ree);
            }
            catch (Throwable t)
            {
                loggers.log(listener.reference, LogService.LOG_WARNING, "Listener threw exception", t);
                LOGGER.log(Level.WARNING, "Listener threw exception", t);
            }
            finally
            {
                if (future != null) future.cancel(false);
                if (latch != null) latch.countDown();
            }
        }
View Full Code Here

        pool.initialize(10);
        System.out.println("About to execute new thread immediately");
        pool.execute(new MyTest("Executing immediately"));

        //ScheduledFuture sf = pool.schedule(new MyTest("Should execute in 30 seconds"), 30, TimeUnit.SECONDS);
        ScheduledFuture sf2 = pool.scheduleAtFixedRate(new MyTest("Should execute every 3 seconds after 10"), 10, 3, TimeUnit.SECONDS);
        ScheduledFuture sf3 = pool.schedule(new MyTest("Should never execute because cancelled"), 60, TimeUnit.SECONDS);
        Thread.sleep(30 * 1000);
        sf3.cancel(false);
        pool.schedule(new MyTest("Should execute after about 40 total seconds"), 5, TimeUnit.SECONDS);
        sf2.cancel(false);
        System.out.println("all done");
        Thread.sleep(30 * 1000);
        System.exit(-1);
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Test
    public void scheduleWithFixedDelay() {
        @SuppressWarnings("rawtypes")
        ScheduledFuture expected = mock(ScheduledFuture.class);
        Runnable task = mock(Runnable.class);
        long delay = 10L;
        long period = 20L;
        TimeUnit unit = TimeUnit.SECONDS;
View Full Code Here

        }

        @Override
        public Date getNextRunTime(LastExecution lastExecution, Date taskScheduledTime) {
            Date nextRunTime = trigger.getNextRunTime(lastExecution, taskScheduledTime);
            final ScheduledFuture future = this.future;
            if (future != null && future.isCancelled()) {
                nextRunTime = null;
            }
            return nextRunTime;
        }
View Full Code Here

TOP

Related Classes of java.util.concurrent.ScheduledFuture

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.