Re: Unlimited threads being created
Hugo wrote:
Thank you for your post.
Also, how many hardware execution units ("CPU's," "cores,"
"strands") does your system have,
CPUs: 2 x 1002Mhz
Memory size: 4GB
Operating system: Solaris 9
You don't mention the CPU type, which matters a lot,
but in any event the number of threads that can execute
simultaneously on the hardware will not be close to a
thousand. You could likely count them on your fingers;
taking your shoes off is probably unnecessary.
Why didn't the Executor recycle through the threads created via:
ExecutorService pool = Executors.newFixedThreadPool(1000)?
Why do you think it didn't? My suspicion (until proven
otherwise, and proofs are certainly possible) is that it
never got to a thousand in the first place, but ran out of
memory before it could create that many threads.
The ExecutorService is declared in the class field and not in the
doPost() method, will this be an issue?
It's in the Foo constructor (well, sort of: what you
showed is obviously a paraphrase -- it wouldn't compile,
for starters -- so I can't be sure just where the pool
is created). But let's suppose it's in Foo's constructor,
and that Foo is an HTTPServlet. That means you'll get a
new pool each time an HTTPServlet/Foo instance is created.
I don't know how frequently Tomcat does so -- I seem to
recall that it ordinarily creates a given servlet type
only once, but that there may be ways of unloading and
reloading them, or ways of starting multiple instances
under different aliases. So you'll have at least one pool
with a "ceiling" of a thousand threads, possibly N such
pools.
I say again: Reduce the thread count, maybe to ten or
twenty-ish. What benefit do you expect from a thousand
threads all trying to elbow each other out of the way for
the attention of two processor chips?
--
Eric.Sosman@sun.com