tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leon Rosenberg" <>
Subject Re: jvm cowardly refuses to print a thread dump
Date Fri, 05 Dec 2008 09:32:18 GMT
On Fri, Dec 5, 2008 at 9:50 AM, Oliver Schoett
<> wrote:
> Martin Gainty wrote:
>> so the solution is put all updates/inserts to the arraylist into a
>> synchronized method?
> You must synchronize all read and write methods, because nothing may run in
> parallel with a write method, and so read methods must be prevented from
> executing if a write method runs already.
> The only exception is if you can ensure that the ArrayList is read-only at
> some point in your program (e. g., after a setup phase).
> Arguing that the size() function cannot loop does not help, because the size
> function could be called internally in an infinite loop (this would be
> visible in the call stack).

I'm very sorry but i really don't see your point.
The only possible need to synchronize access to ArrayList.size is when
you a) access the list from different threads and b) need the result
to be exact. Neither was the fact in my original post, in fact, as we
already resolved it, the vm was getting out of old gen space and
afterwards just behaving weird.
In 99% of the cases you don't need to synchronize calls to ArrayList,
because usually you will use it in a local scope or single thread. And
you definitely don't need to synchronize .size(), the worst thing that
can happen is that the result is inaccurate, because another thread
just removed or added something (except for reasons stated in first
part of the mail).


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message