Online Java Compiler By
JavaTpoint.com
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadPoolExecutor; import java.lang.Thread; import java.util.logging.Level; import java.util.logging.Logger; public class ThreadPoolExecutorremoveExample2 { public static void main(String[] args) { Workkk task1 = new Workkk("t1"); System.out.println("Starting threads"); ThreadPoolExecutor tExecutor = (ThreadPoolExecutor) Executors.newCachedThreadPool(); tExecutor.submit(task1); tExecutor.execute(task1); // start task1 tExecutor.remove(task1); tExecutor.shutdown(); // shutdown worker threads } } class Workkk implements Runnable { private final String threadName; public Workkk(String threadName) { this.threadName = threadName; } @Override public void run() { for(int i=4 ; i<=9;i++) { if(i==5) { System.out.println("i=" +i); } } } }
Output