4 Replies Latest reply on Aug 26, 2009 12:36 PM by Stratos Pavlakis

    Handling ThreadDeath in JBoss ThreadPool

    R Vince Newbie

      I am using JBoss 5.1GA (the version for JDK 6), and using the ThreadPool provided. I have socket listener that is running in a thread, wherein I want a maximum time it can be connected, and when that time is up, to disconnect and release the thread. So I set up as:

      this.threadPool.getInstance().run(connHandle, 0, max_millisseconds_allowed);

      Which spanws the thread properly

      However, after max_millisseconds_allowed is up, I am getting

      WARN [RunnableTaskWrapper] Unhandled throwable for runnable: com.sparkbase.ts.listener.ConnHandle@19d477f3
      at java.lang.Thread.stop(Thread.java:732)
      at org.jboss.util.threadpool.RunnableTaskWrapper.stopTask(RunnableTaskWrapper.java:122)
      at org.jboss.util.threadpool.BasicThreadPool$TimeoutInfo.stopTask(BasicThreadPool.java:631)
      at org.jboss.util.threadpool.BasicThreadPool$TimeoutMonitor.run(BasicThreadPool.java:694)
      at java.lang.Thread.run(Thread.java:636)

      My question is how do I handle this? Can I just let it go (the system seems to run fine afterwards -- but maybe I have thread leakage?). How do you handle this "ThreadDeath" throwable in a try-catch block, and what do you do with it afterwards. I need to maintain the integrity of the JBoss ThreadPool.

      Thanks, RVince. p.s. If I am in the wrong forum, can you please point me to the correct one?

        • 1. Re: Handling ThreadDeath in JBoss ThreadPool
          Stratos Pavlakis Newbie

          Hi there,

          well I don't have an answer cause I am 1 step behind. So I 'll ask for your help here. Please check what I posted a few hours before you

          How do you use the ThreadPool provided by JBoss in your code? Is this a BasicThreadPool configured to be used only by your application?

          You mention : this.threadPool.getInstance() ... What kind of object is "this"?

          I know you 'd prefer an answer but I had a question :)


          • 2. Re: Handling ThreadDeath in JBoss ThreadPool
            R Vince Newbie

            import org.jboss.util.threadpool.BasicThreadPool;
            private BasicThreadPool threadPool;
            //connHandle implements Runnable

            It's that simple. See the api for what you can do then with threadPool in terms of setting max size, etc.

            • 3. Re: Handling ThreadDeath in JBoss ThreadPool
              Stratos Pavlakis Newbie

              Thx a lot. I 'll give it a try and I may come up with feedback.

              • 4. Re: Handling ThreadDeath in JBoss ThreadPool
                Stratos Pavlakis Newbie

                Well, after googling some more and after seeing no replies on my post I have to say it's hard stuff to find answers for.


                Let's say that we don't mind coupling with Jboss classes, or that we build a generic AS adapter so that we loose it a bit.

                import org.jboss.util.threadpool.BasicThreadPool;
                private BasicThreadPool threadPool;

                First of all I guess that you instantiate "threadPool" by getting access to a BasicThreadPool Mbean, let's say the default like that:

                ObjectName objectName = new ObjectName("jboss.jca:service=WorkManagerThreadPool");

                BasicThreadPool mbean =

                Well, that's suitable for problems of low complexity in my opinion. For example, if I know beforehand that I want 3 pools for my application, I can define 3 separate pools in my jboss-service.xml with known names so that I can access them in my code etc.

                In my case, I have a dynamic list of "monitors", each with its own "agents" running on a separate thread (1 thread per agent). I want each monitor's threads though, to belong to the same threadgroup, named after the name of the monitor. (i.e. Monitor 1 - Agents Group)
                Each monitor is an Mbean itself. Agents are classes of a simple interface with a single method like dosomething();

                I came up with the following actually, don't know if it's right though...
                Each monitor Mbean of mine, should dynamically create and register with the server a BasicThreadPool MBean. The BasicThreadPool constructor accepts a ThreadGroup. Why is it so important to have agents belonging to specific threadgroups? Well I just want my threads fixed up and settled, thus easily monitored.

                What do you think of this? I am actually afraid of it :P

                Btw, the only reason I want to do this is to try to stick to specs saying that we should not create user threads inside application servers. (The servlet spec permits it though). It works just fine with user threads created in MBeans until now, it seems I want to punish myself :)

                Now, as for your issue, I don't know if you have access to the classes code, or if you can extend them but I think that you could fix this another way.

                Don't run your runnables with specified timeout on the threadpool.run(...) method. You could pass them a timeout upon instantiation as a parameter. Then you could make your runnables check every t secs if the timeout has been reached or exceeded, and if so they should return; For this to work effectively I guess your runnables code should be instrumented in a way that it checks the enabled flag often enough. Same principle as using sleep() and interrupts.

                That's all for now.