X-Git-Url: http://dolda2000.com/gitweb/?p=jsvc.git;a=blobdiff_plain;f=src%2Fdolda%2Fjsvc%2FThreadContext.java;h=2d9931e9d35c521d15baaff6da44ef801052d0c2;hp=78a5d4e87578d5ce8e7b6445500ae31b75e56bc7;hb=4b8346e1aad3c58196f8d4dadf9da6726f66f5f4;hpb=d7bc1a7a5f8c82911f7504903cfbfd956b216022 diff --git a/src/dolda/jsvc/ThreadContext.java b/src/dolda/jsvc/ThreadContext.java index 78a5d4e..2d9931e 100644 --- a/src/dolda/jsvc/ThreadContext.java +++ b/src/dolda/jsvc/ThreadContext.java @@ -7,10 +7,12 @@ public class ThreadContext extends ThreadGroup { private Logger logger = Logger.getLogger("dolda.jsvc.context"); private ThreadGroup workers; private long reqs = 0; + private final ServerContext ctx; public final Responder root; - public ThreadContext(ThreadGroup parent, String name, Class bootclass) { + public ThreadContext(ThreadGroup parent, String name, ServerContext ctx, Class bootclass) { super((parent == null)?(Thread.currentThread().getThreadGroup()):parent, name); + this.ctx = ctx; workers = new ThreadGroup(this, "Worker threads") { public void uncaughtException(Thread t, Throwable e) { logger.log(Level.SEVERE, "Worker thread terminated with an uncaught exception", e); @@ -23,6 +25,10 @@ public class ThreadContext extends ThreadGroup { logger.log(Level.SEVERE, "Service thread " + t.toString() + " terminated with an uncaught exception", e); } + public ServerContext server() { + return(ctx); + } + public void shutdown() { if(root instanceof ContextResponder) ((ContextResponder)root).destroy(); @@ -88,4 +94,12 @@ public class ThreadContext extends ThreadGroup { } return(res[0]); } + + public static ThreadContext current() { + for(ThreadGroup tg = Thread.currentThread().getThreadGroup(); tg != null; tg = tg.getParent()) { + if(tg instanceof ThreadContext) + return((ThreadContext)tg); + } + return(null); + } }