package org.jretty.util;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 
 * @author zollty
 * @since 2018年5月25日
 */
public class NamedThreadTest {
    
    public static void main(String[] args) throws InterruptedException {
        
        NamedThreadFactory factory = new NamedThreadFactory("apollo", true);
        
        ExecutorService es = Executors.newFixedThreadPool(10, factory);
        
        Runnable r = new NamedRunnable() {
            
            @Override
            public void run() {
                ThreadUtils.sleepThread(15000);
            }

            @Override
            public String getName() {
                return "apolloTask";
            }
        };
        es.execute(r);
        es.execute(r);
        es.execute(r);
        es.execute(r);
        es.execute(r);
        
        factory = new NamedThreadFactory("apollo", true);
        factory.newThread(r).start();
        
        factory = new NamedThreadFactory("AsyncRunAfterStart_Thread", false);
        factory.newThread(new Runnable() {
            @Override
            public void run() {
                ThreadUtils.sleepThread(15000);
            }
        }).start();
        
        
        es.awaitTermination(20000, TimeUnit.MILLISECONDS);
        es.shutdownNow();
    }

}

@@ -628,32 +628,113 @@
 pThread(15000);%0A
+                System.out.println(Thread.currentThread().getName() + %22 done!%22);%0A
             %7D%0A%0A 
@@ -881,36 +881,52 @@
 r);%0A        
-es.execute(r
+ThreadUtils.sleepThread(1000
 );%0A        e
@@ -943,36 +943,52 @@
 r);%0A        
-es.execute(r
+ThreadUtils.sleepThread(1000
 );%0A        e
@@ -1013,102 +1013,121 @@
     
-%0A        factory = new NamedThreadFactory(%22apollo%22, true);%0A        factory.newThread(r).start(
+ThreadUtils.sleepThread(1000);%0A        es.execute(r);%0A        ThreadUtils.sleepThread(1000);%0A        es.execute(r
 );%0A 
@@ -1401,32 +1401,58 @@
       %0A        %0A
+        test2();%0A        %0A
         es.await
@@ -1525,12 +1525,867 @@
 );%0A    %7D
+%0A    %0A    public static void test2() throws InterruptedException %7B%0A        NamedThreadFactory factory = new NamedThreadFactory(%22apollo%22, true);%0A        factory.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() %7B%0A            @Override%0A            public void uncaughtException(Thread t, Throwable e) %7B%0A                System.out.println(%22--------------%22 + e.toString());%0A            %7D%0A        %7D);%0A        factory.newThread(new NamedRunnable() %7B%0A            %0A            @Override%0A            public void run() %7B%0A                ThreadUtils.sleepThread(15000);%0A                System.out.println(Thread.currentThread().getName() + %22 done!%22);%0A                throw new IllegalAccessError();%0A            %7D%0A%0A            @Override%0A            public String getName() %7B%0A                return %22apolloTask%22;%0A            %7D%0A        %7D).start();%0A    %7D
 %0A%0A%7D%0A

add named thread