JavaWorld
addict
Reged: 06/20/03
Posts: 482
|
|
Pool resources using Apache's Commons Pool Framework
|
Anonymous
Unregistered
|
|
Hi,
First, I think it's a cool framework! But I have some questions to the author: Is there a reason for why you wait on a dummy synObj? Wouldn't it be easier and safer to just join the thread? Imagine some other threads are interested on the completition of the task. It might happen that they wait on the object even if the task has alredy completed.
(in execution order!) thread 1. start task thread 1. notifyAll thread 2. syObj.wait()
|
Murali Kosaraju
Unregistered
|
|
If you use join(), the calling thread waits for ever, since the callee thread (the running pooled thread), never finishes the run() method. Only when we call the destroy() method, through the framework, the callee thread completes its run() method. After all, the main purpose of pooling the threads is to keep them running for as long as the pool requires.
join() method can be useful, when you are spawning a thread, that is not pooled, and wait for it to finish. Murali
|
Anonymous
Unregistered
|
|
Ah you are right with that. I didn't check the whole code. But the problem with the synObj remains! At least you should check the task before you call wait() on it
synchronized (task) { while(!task.hasFinished()) { task.wait(); } }
|
Anonymous
Unregistered
|
|
That is not a problem but the code is safe, yes.
-Murali
|
parachu
stranger
Reged: 05/17/05
Posts: 3
|
|
Hi All!
In my application I have all the configuration of my command objects in an xml file, on application startup I have a singleton class which reads data from the xml file and creates a command registry (hash table) which now contains information about each command, i.e name of a command, any helper classes needed to execute that command etc.
Next time when I have to execute a command (coming from a client) I get the Command info from the command registry; have to usually execute a query on command registry e.g.
commandRegistary.getCommandInfo(“Login”) This will give me a commandInfo object from which I know that which class I have to dynamically load for this particular command (and set it’s attributes I got from client).
The main point in the above story is, I am using a singleton class for this purpose and wondering weather I should stick with this approach or create a pool of instatnces of this class and then use those instances in my application?.
Feeling embarrassed to tell you that I can’t figure out the situations where I should use resource pooling and where I should avoid pooling resources. Yes I know about Connection/Thread pooling infect have been using those techniques but in the current case cant figure out should or shouldn’t I use resource pooling here.
|
Athen
journeyman
Reged: 06/05/07
Posts: 79
Loc: San Francisco, CA
|
|
Hi Parachu,
You might want to try posting this question to the general forums. This article was published a couple of years ago, so the thread attached to it doesn't get near as much traffic as, say, the Enterprise Java forum. http://www.javaworld.com/javaforums/ubbthreads.php
-------------------- Athen O'Shea
Editor, JavaWorld.com
|