On Sat, Jul 21, 2012 at 11:44:43AM -0700, Ted Dunning wrote: > Synchronization in low level code is generally really bad. This is the > whole point of why Vector was essentially thrown away in Java collections > in favor of ArrayList.
I might be wrong, but I don't think that's the reason. At the beginning there was the "Vector"... and nothing else. In singly threaded code or as a thread local variable, synchronization is an unnecessary waste of time. Since most code falls into this category, "ArrayList" is indeed much more useful. That doesn't imply that there is never a need for synchronization in low-level code. In the present case, AFAICT the synchronization is a performance gain during the creation of the data (to be cached). Once that part is done, user code do not call any "synchronized" methods, so no loss there. > > Better to synchronize in the caller who knows about the multi-threading. > Or simply build a synchronized wrapper in an inner class. Please show how this fits with the current case, and improves the implementation. Thanks, Gilles > > On Sat, Jul 21, 2012 at 6:08 AM, Gilles Sadowski < > gil...@harfang.homelinux.org> wrote: > > > > > > > Note that there is a performance price for the synchronization, > > > which may outweigh the benefit of adding it. > > > > I thought of adding that because one might want to parallelize the > > integration computations while the quadrature rules factory is shared. > > [See e.g. MATH-827, line 41 in the posted code.] > > Without "synchronized", all threads will compute all the rules. > > > > On my machine (4 cores), in the absence of synchronization, the above test > > indicated that the "computeRule" method was called 18 times! > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org For additional commands, e-mail: dev-h...@commons.apache.org