Online Java Compiler By
JavaTpoint.com
class MYThreadPoolExecutor4 extends ThreadPoolExecutor { public MYThreadPoolExecutor4() { super(1,10,60,TimeUnit.SECONDS,new ArrayBlockingQueue
(1000)); this.allowCoreThreadTimeOut(false); } @Override protected void beforeExecute(Thread thread, Runnable run){ super.beforeExecute(thread, run); if(this.allowsCoreThreadTimeOut()) { try { Object Obj = ((Future>) run).get(); System.out.println(Obj); } catch (InterruptedException | ExecutionException e) { } } else{ System.out.println("Allowtimeout is set to false"); } } } public class ThreadPoolExecuteallowsCoreThreadTimeOutExample2 { public static void main(String args[]){ System.out.println("creating service"); MYThreadPoolExecutor4 obj2 = new MYThreadPoolExecutor4(); Future> sb = obj2.submit(() -> { System.out.println("Welcome to main method"); }); obj2.shutdown(); } }
Output