Online Java Compiler By
JavaTpoint.com
package ThreadPoolExecutorClass; import java.util.concurrent.*; class MYThreadPoolExecutor extends ThreadPoolExecutor { public MYThreadPoolExecutor() { super(1,10,60,TimeUnit.SECONDS,new ArrayBlockingQueue
(1000)); } @Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); if (t == null && r instanceof Future>) { try { Object Obj = ((Future>) r).get(); System.out.println(Obj); } catch (InterruptedException | ExecutionException e) { } } } } public class ThreadPOolExecutorafterExecuteExample2 { public static void main(String args[]){ System.out.println("creating service"); //ExecutorService service = Executors.newFixedThreadPool(10); MYThreadPoolExecutor obj2 = new MYThreadPoolExecutor(); 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