Search in sources :

Example 6 with FixedRateTrigger

use of com.serotonin.timer.FixedRateTrigger in project ma-core-public by infiniteautomation.

the class OrderedRealTimeTimerTest method main.

public static void main(String[] args) {
    OrderedRealTimeTimer timer = new OrderedRealTimeTimer();
    ThreadPoolExecutor executor = new OrderedThreadPoolExecutor(0, 100, 30L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>(), false, timer.getTimeSource());
    timer.init(executor);
    FixedRateTrigger trigger = new FixedRateTrigger(0, 5);
    TimerTask task = new TimerTask(trigger, "task1", "1", 5) {

        private int count = 0;

        @Override
        public void run(long runtime) {
            count++;
            System.out.println("Run: " + count);
            System.out.println("Run at:" + runtime);
            System.out.println("");
            try {
                Thread.sleep(4);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        @Override
        public void rejected(RejectedTaskReason reason) {
            System.out.println("Rejected");
        }
    };
    try {
        Thread.sleep(100);
        timer.schedule(task);
        Thread.sleep(1000000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : OrderedRealTimeTimer(com.serotonin.timer.OrderedRealTimeTimer) FixedRateTrigger(com.serotonin.timer.FixedRateTrigger) TimerTask(com.serotonin.timer.TimerTask) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) OrderedThreadPoolExecutor(com.serotonin.timer.OrderedThreadPoolExecutor) RejectedTaskReason(com.serotonin.timer.RejectedTaskReason)

Aggregations

FixedRateTrigger (com.serotonin.timer.FixedRateTrigger)6 TimeoutTask (com.serotonin.m2m2.util.timeout.TimeoutTask)4 RejectedTaskReason (com.serotonin.timer.RejectedTaskReason)3 OrderedRealTimeTimer (com.serotonin.timer.OrderedRealTimeTimer)2 OrderedThreadPoolExecutor (com.serotonin.timer.OrderedThreadPoolExecutor)2 RealTimeTimer (com.serotonin.timer.RealTimeTimer)2 TimerTask (com.serotonin.timer.TimerTask)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 IntegerMonitor (com.infiniteautomation.mango.monitor.IntegerMonitor)1 ValueMonitorOwner (com.infiniteautomation.mango.monitor.ValueMonitorOwner)1 AnalogStatistics (com.infiniteautomation.mango.statistics.AnalogStatistics)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 MangoThreadFactory (com.serotonin.m2m2.rt.maint.MangoThreadFactory)1 TimeoutClient (com.serotonin.m2m2.util.timeout.TimeoutClient)1 CronTimerTrigger (com.serotonin.timer.CronTimerTrigger)1 TimeSource (com.serotonin.timer.TimeSource)1 ParseException (java.text.ParseException)1 Date (java.util.Date)1 RejectedExecutionHandler (java.util.concurrent.RejectedExecutionHandler)1