Example of defaultThreadFactory in Java
April 18, 2019
java.util.concurrent.Executors
has a method that is defaultThreadFactory
that returns the object of ThreadFactory
.
ThreadFactory tf=Executors.defaultThreadFactory();
Thread th=tf.newThread(ob);
DefaultThreadFactoryTest.java
package com.concretepage; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; public class DefaultThreadFactoryTest { public static void main(String... args){ ThreadFactory tf=Executors.defaultThreadFactory(); Thread th=tf.newThread(new DefaultThreadFactoryTest().new SampleThread() ); th.start(); } class SampleThread implements Runnable { @Override public void run() { int cnt = 0; for (; cnt < 5; cnt++) { System.out.println("run:" + cnt); } } } }