Online Java Compiler By
JavaTpoint.com
package ThreadPoolExecutorClass; import java.util.concurrent.*; class MYThreadPoolExecutor2 extends ThreadPoolExecutor { public MYThreadPoolExecutor2() { super(1,10,60,TimeUnit.SECONDS,new ArrayBlockingQueue
(1000)); } @Override protected void beforeExecute(Thread thread, Runnable run){ super.beforeExecute(thread, run); try { Object Obj = ((Future>) run).get(); System.out.println(Obj); } catch (InterruptedException | ExecutionException e) { } } } public class ThreadPoolExecutorbeforeExecuteExample2 { public static void main(String args[]){ System.out.println("creating service"); //ExecutorService service = Executors.newFixedThreadPool(10); MYThreadPoolExecutor2 obj2 = new MYThreadPoolExecutor2(); Future> sb = obj2.submit(() -> { int a=4, b = 0; System.out.println("a and b="+a+":"+b); System.out.println("a/b:"+(a/b)); System.out.println("Thread Name in Runnable after divide by zero:"+Thread.currentThread().getName()); }); obj2.shutdown(); } }
Output