FlakyThreadFactory.java 文件源码

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

项目:openjdk-jdk10 作者:
void test(final Class<?> exceptionClass,
          final ThreadFactory failingThreadFactory)
        throws Throwable {
    ThreadFactory flakyThreadFactory = new ThreadFactory() {
        int seq = 0;
        public Thread newThread(Runnable r) {
            if (seq++ < 4)
                return new Thread(r);
            else
                return failingThreadFactory.newThread(r);
        }};
    ThreadPoolExecutor pool =
        new ThreadPoolExecutor(10, 10,
                               0L, TimeUnit.SECONDS,
                               new LinkedBlockingQueue(),
                               flakyThreadFactory);
    try {
        for (int i = 0; i < 8; i++)
            pool.submit(new Runnable() { public void run() {} });
        check(exceptionClass == null);
    } catch (Throwable t) {
        /* t.printStackTrace(); */
        check(exceptionClass.isInstance(t));
    }
    pool.shutdown();
    check(pool.awaitTermination(LONG_DELAY_MS, MILLISECONDS));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号