Summarize the use of the four common thread pools that the JDK takes with you
Package thread.pool;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
Import Java.util.concurrent.ScheduledExecutorService;
Import Java.util.concurrent.TimeUnit;
public class Threadpoolutil {static Executorservice cachedthreadpool;
Static Executorservice Fixedthreadpool;
Static Scheduledexecutorservice Scheduledthreadpool;
Static Executorservice Singlethreadpool; Static Executorservice Cachedthreadpoolrun (Runnable Runnable) {if (Cachedthreadpool = null) cachedth
Readpool = Executors.newcachedthreadpool ();
Cachedthreadpool.submit (runnable);
return cachedthreadpool;
public static Executorservice Fixedthreadpoolrun (Runnable Runnable) {if (Fixedthreadpool = null)
Fixedthreadpool = Executors.newfixedthreadpool (Runtime.getruntime (). Availableprocessors ());
Fixedthreadpool.submit (runnable);
return fixedthreadpool; } pUblic static Executorservice Scheduledthreadpoolrun (Runnable Runnable, long delay, timeunit unit) {if (Scheduledt
Hreadpool = = null) Scheduledthreadpool = Executors.newscheduledthreadpool (Runtime.getruntime ()
. Availableprocessors ());
Scheduledthreadpool.schedule (runnable, delay, unit);
return scheduledthreadpool;
public static Executorservice Singlethreadpoolrun (Runnable Runnable) {if (Singlethreadpool = null)
Singlethreadpool = Executors.newsinglethreadexecutor ();
Singlethreadpool.submit (runnable);
return singlethreadpool;
public static void Main (string[] args) {final Long starttime = System.currenttimemillis ();
Executorservice executorservice = null;
for (int i = 0; i < 1000000 i++) {//System.out.println (Finali);
final int finali = i;
Runnable task = ()-> System.out.println (Finali); ExecUtorservice = Threadpoolutil.fixedthreadpoolrun (Task);
} if (Executorservice!= null) {Executorservice.shutdown (); } while (true) {if (executorservice.isterminated ()) {System.out.println ("All child threads are ended" 。
");
Break
} final Long stoptime = System.currenttimemillis ();
System.out.println ("---------------------------");
System.out.println (Stoptime-starttime); }
}