Brian Goetz wrote:
>
> This statement is true, but very easy to misinterpret; be careful.
> You can't use this to make an end-run around the problem in the
> general case.  If jspx_init() creates any objects, you've gotta
> synchronize, plain and simple.  If jspx_init() calculates
> multiple primitive values, which can obtained through any other
> means than its return value, you've gotta synchronize.

Hmm.  Obviously this subject is much more subtle that I expected.  Thanks
for the clarification, and in particular, the patient way in which you
presented it.

Can we back up for a moment?

I presume that synchronization is a relatively expensive operation,
particularly on a high end, multiprocessor box?  I also presume that the
throughput in terms of requests per second that a given servlet engine
processes is an important measure.

If it turns out that either of those two assertions are false (in
particular if it turns out that the overhead of a synchronize is negligible
compared to the overhead of the processing of a request), then we might as
well do the simple and clean thing and remove the unsafe if checks.

Otherwise, it behooves us to look for alternatives.  One suggested by the
web page is to put the code into a static initializer for a class as this
apparently is guaranteed to be safe.

If for some reason this turns out to be impractical, then another obvious
solution would be to move all initialization to the point in the program
prior to where any threads are created.  Might break some architectural
boundaries, but with enough inventive people around, this can perhaps be
isolated and encapsulated appropriately.

Anybody have any hard data on the validity of the presumptions above?

- Sam Ruby


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

Reply via email to