Paulo Gaspar wrote:
>
> Bruce Eckel on his book "Thinking in Java" states that a simple
> method call (no parameters) takes 5.9 units of time while a
> synchronized method call takes 570. OTOH, object creation takes
> 980 which makes it an even worse alternative.

Normally I would say that numbers such as these should be taken with a
grain of salt.  For example, object creation has side effects that will
affect the times of subsequent garbage collections; and synchronization can
affect the performance of other threads.

However, if a synchronized method call takes on the order of the time of an
object creation (which makes sense as object creation is likely
synchronized itself), then I would be inclined to say that this overhead is
quite small compared to the overall processing of an HTTP request as such
involves the creation of a quite large number of objects.  So, if a
relatively small number of these operations were done per request, then the
right course of action would be to replace the code with the safest,
simplest, and most maintainable alternative, namely a simple
synchronization block without the outer if statement.

I'm convinced.

- Sam Ruby


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to