ro.isdc.wro.util
Class SchedulerHelper

java.lang.Object
  extended by ro.isdc.wro.util.SchedulerHelper

public class SchedulerHelper
extends Object

Encapsulates the logic which handles scheduler creation and destroy. This class is thread-safe.

Since:
1.4.2
Author:
Alex Objelean

Method Summary
static SchedulerHelper create(LazyInitializer<Runnable> runnableFactory)
           
static SchedulerHelper create(LazyInitializer<Runnable> runnableFactory, String name)
          Factory method.
 void destroy()
          Stops all jobs runned by the scheduler.
 SchedulerHelper scheduleWithPeriod(long period)
          Schedules with provided period using TimeUnit.SECONDS as a default time unit.
 SchedulerHelper scheduleWithPeriod(long period, TimeUnit timeUnit)
          Run the scheduler with the provided period of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static SchedulerHelper create(LazyInitializer<Runnable> runnableFactory,
                                     String name)
Factory method. Creates a SchedulerHelper which consumes a factory providing a runnable. This approach allows lazy runnable initialization.

Parameters:
runnableFactory - a factory creating the runnable to schedule.
name - the name associated with this SchedulerHelper (useful to detect if this class is causing a memory leak.

create

public static SchedulerHelper create(LazyInitializer<Runnable> runnableFactory)
See Also:
SchedulerHelper#create(ObjectFactory, String)

scheduleWithPeriod

public SchedulerHelper scheduleWithPeriod(long period,
                                          TimeUnit timeUnit)
Run the scheduler with the provided period of time. If the scheduler is already started, it will be stopped (not before the running job is complete).

Parameters:
period - new period for scheduling.
timeUnit - what kind of time unit is associated with the period.

scheduleWithPeriod

public SchedulerHelper scheduleWithPeriod(long period)
Schedules with provided period using TimeUnit.SECONDS as a default time unit.

Parameters:
period - new period for scheduling.

destroy

public void destroy()
Stops all jobs runned by the scheduler. It is important to call this method before application stops.



Copyright © 2008-2013. All Rights Reserved.