MissingNotificationTest.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:jdk8u-jdk 作者:
public static void main(String[] args) throws Exception {
    System.out.println(
        ">>> Test for missing notifications.");

    System.out.println(">>> Create a Timer object.");
    final Timer timer = new Timer();

    timer.start();

    NotifListener listener = new NotifListener();
    timer.addNotificationListener(listener, null, null);

    ExecutorService executor = Executors.newFixedThreadPool(100);
    final Random rand = new Random();


    for (int i = 0; i < TASK_COUNT; i++) {
        executor.execute(new Runnable() {
            public void run() {
                long dateMillis = System.currentTimeMillis() + fixedDelay + rand.nextInt(2000);
                Date date = new Date(dateMillis);
                timer.addNotification("type", "msg", "userData", date);
            }
        });

    }

    executor.shutdown();
    executor.awaitTermination(20, TimeUnit.SECONDS);

    waitForNotificationsToEnd(listener);

    timer.stop();

    if (listener.count < TASK_COUNT) {
        throw new RuntimeException("Not fired: " + (TASK_COUNT - listener.count));
    } else {
        System.out.println(">>> All notifications handled OK");
    }

    System.out.println(">>> Bye bye!");
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号