Java concurrency

Hi,

I'm currently working on creating a threadpool that uses the worker thread pattern. I have a listener of sorts that receives tasks which are then fed to

ThreadPoolExecutor class. The code for this is shown below:

executor.execute(new ListenerQueueProcessor(key, value));

The run method of the ListenerQueueProcesser (The worker thread) is show here:

publicvoid run()

{

cacheStore.store(key, value);

}

I just have a question about how this should be working. Basically I have limited my ThreadPoolExecutor to a fixed thread pool of 10 threads. I have exposed this whole class using JMX so that I can monitor how may threads are running, the current queue etc etc. It seems that I only ever have one thread running. Could this be because the task I am giving it doesn't warrant creating another thread? If I place a Thread.sleep(2500) in my threads run() method, just to simulate a bit more work, it does go ahead and create the 10 threads when I bombard it with events.

Is there something I'm doing wrong or is it working as it should?

Is there a way to specify the wait a new task will wait for before deciding that it would be best to create a new thread?

[1388 byte] By [Richcoleuka] at [2007-11-27 10:16:14]
# 1

If all your threads are doing is storing a value in a map, then why do you want to use multiple threads anyway? If the system can get it done without using multiple threads, then let it. Like you said, if the tasks take longer, it uses multiple threads, but if it doesn't need to, don't worry about it.

hunter9000a at 2007-7-28 15:44:24 > top of Java-index,Java Essentials,Java Programming...
# 2

I'm not storing values in a map.

I was just concerned that I could get better performance but increasing the ease at which new threads are utilised.

Also in my code when I call execute I create a new thread. Is this correct? As I thought the idea of the threadpool is that i has a set of threads ready to go and only uses these instances?

Richcoleuka at 2007-7-28 15:44:24 > top of Java-index,Java Essentials,Java Programming...