Beispiel #1
0
 /**
  * Obtain the default global timer from the current context. The globalTimer is created lazily so
  * it is preferrable to fetch them out of the critical path.
  *
  * <p>The global timer will also ignore {@link Timer#cancel()} calls and should be cleaned using
  * {@link #unregister()} ()}.
  *
  * <p>The default globalTimer is a {@link HashWheelTimer}. It is suitable for non blocking
  * periodic work such as eventing, memory access, lock-free code, dispatching...
  *
  * @return the globalTimer, usually a {@link HashWheelTimer}
  */
 public static Timer get() {
   GlobalTimer t = context.timer;
   while (null == t) {
     t = new GlobalTimer();
     if (!GLOBAL_TIMER.compareAndSet(context, null, t)) {
       t = context.timer;
       t._cancel();
     } else {
       t.start();
       break;
     }
   }
   return t;
 }
Beispiel #2
0
 /**
  * Clean current global timer references and cancel the respective {@link Timer}. A new global
  * timer can be assigned later with {@link #get()}.
  */
 public static void unregister() {
   GlobalTimer timer;
   while ((timer = GLOBAL_TIMER.getAndSet(context, null)) != null) {
     timer._cancel();
   }
 }