X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=lib%2Fjetty%2Forg%2Feclipse%2Fjetty%2Futil%2Fthread%2FScheduledExecutorScheduler.java;h=70cb518c60b194c03746072a174d15cc6857b68c;hp=5f8d62a65ac356deeead2d62d1d31a3df5695436;hb=ba4f228fa9f72d50991a2218cfd83987ef5d385e;hpb=875b5e9651498a0cd8e0001c0742ba843e47cad0 diff --git a/lib/jetty/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java b/lib/jetty/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java index 5f8d62a6..70cb518c 100644 --- a/lib/jetty/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java +++ b/lib/jetty/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java @@ -1,6 +1,6 @@ // // ======================================================================== -// Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. +// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd. // ------------------------------------------------------------------------ // All rights reserved. This program and the accompanying materials // are made available under the terms of the Eclipse Public License v1.0 @@ -18,12 +18,17 @@ package org.eclipse.jetty.util.thread; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.component.AbstractLifeCycle; +import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; /** * Implementation of {@link Scheduler} based on JDK's {@link ScheduledThreadPoolExecutor}. @@ -33,21 +38,29 @@ import org.eclipse.jetty.util.component.AbstractLifeCycle; * queue even if the task did not fire, which provides a huge benefit in the performance * of garbage collection in young generation. */ -public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler +public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Scheduler, Dumpable { private final String name; private final boolean daemon; + private final ClassLoader classloader; private volatile ScheduledThreadPoolExecutor scheduler; + private volatile Thread thread; public ScheduledExecutorScheduler() { this(null, false); - } + } public ScheduledExecutorScheduler(String name, boolean daemon) + { + this (name,daemon, Thread.currentThread().getContextClassLoader()); + } + + public ScheduledExecutorScheduler(String name, boolean daemon, ClassLoader threadFactoryClassLoader) { this.name = name == null ? "Scheduler-" + hashCode() : name; this.daemon = daemon; + this.classloader = threadFactoryClassLoader; } @Override @@ -58,8 +71,9 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch @Override public Thread newThread(Runnable r) { - Thread thread = new Thread(r, name); + Thread thread = ScheduledExecutorScheduler.this.thread = new Thread(r, name); thread.setDaemon(daemon); + thread.setContextClassLoader(classloader); return thread; } }); @@ -78,10 +92,37 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch @Override public Task schedule(Runnable task, long delay, TimeUnit unit) { - ScheduledFuture result = scheduler.schedule(task, delay, unit); + ScheduledThreadPoolExecutor s = scheduler; + if (s==null) + return new Task(){ + @Override + public boolean cancel() + { + return false; + }}; + + ScheduledFuture result = s.schedule(task, delay, unit); return new ScheduledFutureTask(result); } + @Override + public String dump() + { + return ContainerLifeCycle.dump(this); + } + + @Override + public void dump(Appendable out, String indent) throws IOException + { + ContainerLifeCycle.dumpObject(out, this); + Thread thread = this.thread; + if (thread != null) + { + List frames = Arrays.asList(thread.getStackTrace()); + ContainerLifeCycle.dump(out, indent, frames); + } + } + private class ScheduledFutureTask implements Task { private final ScheduledFuture scheduledFuture;