how many thread pools are there really?

80 views
Skip to first unread message

pohl

unread,
Mar 31, 2012, 7:58:08 PM3/31/12
to hawtdispatch
Hiram,

I am trying to wrap my mind around hawtdispatch, and I have reached
the point where I think I need you to answer a question in order for
my understanding to progress.

I understand that hawtdispatch is indented to be a single system-wide
thread pool modeled after libdispatch, and I often encounter
statements to this effect. For example, here's a recent question on
stack overflow where you recently maintained that point:

http://stackoverflow.com/questions/9322252/how-is-hawtdispatch-different-from-javas-executors-and-netty

Similarly, the javadoc in Dispatch.java says: "All dispatch queues
use a shared fixed size thread pool to execute tasks".

However, when I explore the source code, it's hard for me to
understand how this is implemented. For example, I start by reading
the SimplePool.java source, and I notice that its constructor is
called from the constructor GlobalDispatchQueue.java, which is (in
turn) instantiated HawtDispatcher.java in the following two methods:

getGlobalQueue()
getGlobalQueue(DispatchPriority priority)

Since there are three different priorities, it seems like there would
be up to 3 instances of SimplePool that end up being created behind
the scenes.

Could you help me understand the apparent mismatch here? Are you
considering these 3 instances of SimplePool to collectively be the
single meta-pool that you refer to as the "shared" thread pool?

Also, I'm curious to what extent the three different DispatchPriority
levels depend upon Thread.MAX_PRIORITY, Thread.NORM_PRIORITY, and
Thread.MIN_PRIORITY. There's a pretty pessimistic article here that
makes it seem that I'd have to run my JVM as root and launch it with a
special flag in order for these thread priorities to mean anything on
Linux.

http://www.javamex.com/tutorials/threads/priority_what.shtml

Do you have any thoughts on that?

Hiram Chirino

unread,
Apr 1, 2012, 9:24:58 AM4/1/12
to hawtdi...@googlegroups.com
You get a fix size thread pool for each dispatch priority being used.  The threads in each pool will have the thread priority set to match the dispatch priority.  I tend to just use the Default dispatch priority in my apps so I can't comment on how well thread priorities work on linux.
--

Hiram Chirino

Software Fellow | FuseSource Corp.

chi...@fusesource.com | fusesource.com

skype: hiramchirino | twitter: @hiramchirino

blog: Hiram Chirino's Bit Mojo




Reply all
Reply to author
Forward
0 new messages