> Well I dunno if the code would help, but here is a link to it. I tried
> using the -server option with -Xms2g -Xmx2g. Doesn't do much good.
Chris Uppal kirjoitti:
>> Well I dunno if the code would help, but here is a link to it. I tried
>> using the -server option with -Xms2g -Xmx2g. Doesn't do much good.
[quoted text clipped - 33 lines]
>
> -- chris
After fixing few typos and running it, yes, it does max out both CPU's.
Aki Tuomi
Patricia Shanahan - 23 Apr 2006 15:59 GMT
> Chris Uppal kirjoitti:
>
[quoted text clipped - 3 lines]
>>I think by "a really simple test case" Patricia meant something like
>>(untested):
...
Yes, the deleted code is just the sort of thing I meant.
> After fixing few typos and running it, yes, it does max out both CPU's.
Good. That clarifies things. If running the test program maxes out both
CPU's, and running your real program the same way doesn't, the problem
is a bug in your program.
You are looking for something that forces the threads to run one after
the other, rather than in parallel. It could be something as simple as
calling a thread's run() rather than start(). It could be some
synchronization that affects the most CPU intensive part of the code. It
could be a logical problem involving wait/notify.
Patricia
Chris Uppal - 26 Apr 2006 10:24 GMT
> After fixing few typos and running it, yes, it does max out both CPU's.
I took a quick look at the code you linked to earlier. I'm a bit puzzled.
There's nothing obvious that you are doing which would cause that effect (for
anyone who's interested, Aki's using the new java.util.concurrent package and
between that and the fact that his algorithms work on independent sets of
objects, there's very little need for explicit synchronisation).
One thing that did strike me as worth changing, although I have no idea how it
could affect this problem, is the way that you poll waiting for the list of
tasks to complete. Two much better ways would be:
1) Use awaitTermination() on your thread pool to wait for everything to
complete.
2) Use the semantics of Future objects. If you just loop down your list of
Futures (miscalled "threads" in your code), using get() on each one, then you
you'll be blocked whenever necessary, and won't reach the end of the List until
all the Future tasks have finished.
-- chris