Package test.utils.time

Source Code of test.utils.time.TimerWheelExample

package test.utils.time;

import com.firefly.utils.time.HashTimeWheel;
import com.firefly.utils.time.TimeProvider;

public class TimerWheelExample {
  public void test() {
    final HashTimeWheel t = new HashTimeWheel();
    t.setMaxTimers(5);
    t.setInterval(100);
    t.start();
   
    try {
      Thread.sleep(130L);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    t.add(400, new Runnable() {
      private long start = System.currentTimeMillis();

      @Override
      public void run() {
        long end = System.currentTimeMillis();
        System.out.println("t1: " + (end - start));
      }
    });
   
    t.add(900, new Runnable() {
      private long start = System.currentTimeMillis();

      @Override
      public void run() {
        long end = System.currentTimeMillis();
        System.out.println("t1: " + (end - start));
      }
    });

    t.add(2500, new Runnable() {
      private long start = System.currentTimeMillis();
     
      @Override
      public void run() {
        long end = System.currentTimeMillis();
        System.out.println("t2: " + (end - start));
        t.add(1200, new Runnable() {
          @Override
          public void run() {
            long end = System.currentTimeMillis();
            System.out.println("t2: " + (end - start));
          }
        });
      }
    });
  }

  public static void main(String[] args) throws InterruptedException {
    new TimerWheelExample().test();
    TimeProvider t = new TimeProvider(1000L);
    t.start();
   
    Thread.sleep(1000L);
    long start = t.currentTimeMillis();
    Thread.sleep(5000L);
    System.out.println("TimeProvider: " + (t.currentTimeMillis() - start));
  }
}
TOP

Related Classes of test.utils.time.TimerWheelExample

TOP
Copyright © 2018 www.massapi.com. 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.