-
1. Re: Handling ThreadDeath in JBoss ThreadPool
thehunt Aug 25, 2009 5:34 AM (in response to rvince99)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
http://www.jboss.org/index.html?module=bb&op=viewtopic&t=160259.
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 :)
Thx! -
2. Re: Handling ThreadDeath in JBoss ThreadPool
rvince99 Aug 25, 2009 2:36 PM (in response to rvince99)import org.jboss.util.threadpool.BasicThreadPool;
private BasicThreadPool threadPool;
//connHandle implements Runnable
threadPool.getInstance().run(connHandle);
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
thehunt Aug 26, 2009 10:09 AM (in response to rvince99)Thx a lot. I 'll give it a try and I may come up with feedback.
-
4. Re: Handling ThreadDeath in JBoss ThreadPool
thehunt Aug 26, 2009 12:36 PM (in response to rvince99)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.
Anyway,
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;
threadPool.getInstance().run(runnable);
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 =
(BasicThreadPool)MBeanServerInvocationHandler.newProxyInstance(
server,
objectName,
BasicThreadPool.class,
false);
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.