-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

To whom it may concern,

Please note that this is a mailing list for users of the Struts web
application framework. Your question is more appropriate elsewhere.

That being said, we tend to know a lot about Java...

temp temp wrote:
> I am using a synchronized block and need help using it.
> 
> I have a singleton class which has a global variable Map. I will
> updating this Map at runtime.

I assume that you mean that you have a singleton which contains a map.
The map itself is not global... the fact that the class is a singleton
allows you to treat it as if it is a global variable.

>       Example
>               synchronized (fActionHandlers) {
>       fActionHandlers.put(
>           vAction.getClassName(),  
>           vConfigAction);
>   }
>
> I want this update to be synchronized. The above code is this right?

That depends. Is "fActionHandlers" the map you want to protect? If so,
then your code is correct. Another option is to use a Map that is
already synchronized (such as a Hashtable) or add synchronization to
your Map using java.util.Collections.synchronizedMap.

> My assumption about this is JVM will allow only one thread at a time
> to execute the code in the synchronized block is this right ?

The JVM will only allow one thread to execute that code /for the object
used as the monitor/ -- that is, as long as "fActionHandlers" is always
a reference to the the same object.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGAAi69CaO5/Lv0PARAhoiAKCKqA1tI9lAjaDHnIlNy6M5wSbakgCgwFRB
46yOi9fT3L0/jaN1Sn79UM0=
=huj5
-----END PGP SIGNATURE-----

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

Reply via email to