Package org.jboss.errai.bus.server.async

Examples of org.jboss.errai.bus.server.async.TimedTask


    public boolean isAlive() {
        return !thread.isAlive();
    }

    public void run() {
        TimedTask task = null;
        while (active) {
            try {
                long tm;
                while (active) {
                    timeSampleStart = nanoTime();
                    if ((task = pool.getNextTask()) == null) {
                        continue;
                    }

                    tm = nanoTime();
                    task.run();
                    cpuTime = (nanoTime() - tm);

                    calculateLoad();
                }
            }
            catch (InterruptedException e) {
                if (!active) {
                    /**
                     * If the thread has been marked inactive, terminate now.  Otherwise continue along
                     * normally.
                     */
                    return;
                }
            }
            catch (Throwable t) {
                if (task != null) {
                    task.cancel(true);
                }

                if (errorCallback != null) {
                    /**
                     * If the errorCallback is defined for this ThreadWorker, we report the exception we
View Full Code Here


    }

    public AsyncTask schedule(final Runnable runnable, TimeUnit unit, long interval) {
        mutex.lock();
        try {
            TimedTask task;
            scheduledTasks.offer(task = new DelayedTask(runnable, unit.toMillis(interval)));

            return task;
        }
        finally {
View Full Code Here

    }

    public AsyncTask scheduleRepeating(final Runnable runnable, final TimeUnit unit, final long initial, final long interval) {
        mutex.lock();
        try {
            TimedTask task;
            scheduledTasks.offer(task = new RepeatingTimedTask(runnable, unit.toMillis(initial), unit.toMillis(interval)));

            return task;
        }
        finally {
View Full Code Here

    }

    private long runAllDue() throws InterruptedException {
        long nextRunTime = 0;

        TimedTask task;

        while ((task = scheduledTasks.poll(60, java.util.concurrent.TimeUnit.SECONDS)) != null) {
            if (!task.isDue(currentTimeMillis())) {
                long wait = task.nextRuntime() - currentTimeMillis();
                if (wait > 0) {
                    Thread.sleep(wait);
                }
            }

            /**
             * Sechedule the task for execution.
             */
            if (!queue.offer(task)) {
                throw new QueueOverloadedException("could not schedule task");
            }

            if (task.calculateNextRuntime()) {
                scheduledTasks.offer(task);
            }
        }

        return nextRunTime;
View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.server.async.TimedTask

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.