@Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); ManagedFutureTask task = (ManagedFutureTask) r; try { task.done(t); } finally { task.resetContext(); // Kill thread if thread older than threadLifeTime if (threadLifeTime > 0) { Thread thread = Thread.currentThread(); if (thread instanceof AbstractManagedThread) { long threadStartTime = ((AbstractManagedThread)thread).getThreadStartTime(); if ((System.currentTimeMillis() - threadStartTime)/1000 > threadLifeTime) { throw new ThreadExpiredException(); } } } } }
@Override public void run() { ContextHandle handle = null; try { if (contextHandleForSetup != null) { handle = contextSetupProvider.setup(contextHandleForSetup); } if (shutdown) { // start thread in interrupted state if already marked for shutdown this.interrupt(); } super.run(); } catch (ThreadExpiredException ex) { Logger.getLogger("org.glassfish.enterprise.concurrent").log(Level.INFO, ex.toString()); } catch (Throwable t) { Logger.getLogger("org.glassfish.enterprise.concurrent").log(Level.SEVERE, t.toString()); } finally { if (handle != null) { contextSetupProvider.reset(handle); } removeThread(this); } }
@Override protected void afterExecute(Runnable r, Throwable t) { super.afterExecute(r, t); ManagedScheduledThreadPoolExecutor.ManagedScheduledFutureTask task = (ManagedScheduledThreadPoolExecutor.ManagedScheduledFutureTask) r; try { task.done(t /*task.getTaskRunException()*/); } finally { task.resetContext(); // Kill thread if thread older than threadLifeTime if (threadLifeTime > 0) { Thread thread = Thread.currentThread(); if (thread instanceof AbstractManagedThread) { long threadStartTime = ((AbstractManagedThread)thread).getThreadStartTime(); if ((System.currentTimeMillis() - threadStartTime)/1000 > threadLifeTime) { throw new ThreadExpiredException(); } } } } }