Can't you just fix this by using a ConcurrentHashMap or a ConcurrentReaderHashMap from
the EDU.oswego.cs.dl.util.concurrent package for the expressions?
So the code would be something like:
public static Object compile(String expression) throws OgnlException {
Object o = null;
o = expressions.get(expression);
if (o == null) {
o = Ognl.parseExpression(expression);
expressions.put(expression, o);
}
return o;
}
The map does not store null keys or values so you have to be sure the expression is
not null and the Ognl.parseExpression does not return null.
Cheers,
Dick Zetterberg
[EMAIL PROTECTED]
----- Original Message -----
From: "Patrick Lightbody" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 09, 2003 7:10 AM
Subject: RE: [OS-webwork] Bug catching contest...
> Yeah, I wrote that and recently found out the reasons why it's faulty --
> stupid memory model :)
>
> Can you file a bug on this?
>
> -Pat
>
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Micha� Mosiewicz
> Sent: Tuesday, October 07, 2003 4:01 AM
> To: opensymphony-webwork
> Subject: [OS-webwork] Bug catching contest...
>
> This code won't work as you would expect. It's that kind of bug you
> wouldn't
> expect, but also that kind that should be taught on every programming
> course
> (rare).
>
> For those who are impatient and don't want to find out why it won't work
> I
> suggest googling for "double checked locking" or DCL. Due to java memory
> model (as matter of fact it's not only java) the code below doesn't
> work.
>
> I strongly suggest to pass xwork/webwork through checkstyle. I suppose
> there
> might be more. Of course - in this place it doesn't really matter if it
> synchronized or not - it's just a matter of optimisation. But the same
> idiom
> might be multiplied.
>
> OgnlUtil.compile():
>
> public static Object compile(String expression) throws OgnlException {
> Object o = null;
>
> o = expressions.get(expression);
>
> if (o == null) {
> synchronized (expressions) {
> o = expressions.get(expression);
>
> if (o == null) {
> o = Ognl.parseExpression(expression);
> expressions.put(expression, o);
> }
> }
> }
>
> return o;
> }
>
>
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
SourceForge.net hosts over 70,000 Open Source Projects.
See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
_______________________________________________
Opensymphony-webwork mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/opensymphony-webwork