[concurrency-interest] Synchronizing on AtomicBoolean safe?

David Holmes dholmes at dltech.com.au
Wed Jun 29 12:19:16 EDT 2005


Nikolai,

An AtomicBoolean is just an Object and you can synchronize on it just as you
can any other object.

That said it seems somewhat obscure to use the lock of the AtomicBoolean
this way - if you need a lock object then just declare one:
   Object lock = new Object();
and synchronize on that. It is also unclear from the code snippet why you
want an AtomicBoolean when you are using synchronized blocks anyway??

Cheers,
David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Nikolai
> V. Chr.
> Sent: Thursday, 30 June 2005 12:38 AM
> To: concurrency-interest at altair.cs.oswego.edu
> Subject: [concurrency-interest] Synchronizing on AtomicBoolean safe?
>
>
> Is this sane? If not, how could I do it? I used to use getLock() on
> Lea's old SynchronizedBoolean.
>
> AtomicBoolean protocolSupportEnabled = new AtomicBoolean(false);
>
> synchronized(protocolSupportEnabled) {
>    old = protocolSupportEnabled.getAndSet(enable);
>    if(enable) {
>
> propertyChangeMulticaster.addPropertyChangeListenerIfAbsent(protoc
olListener);
>    } else {
>
> propertyChangeMulticaster.removePropertyChangeListener(protocolListener);
>    }
>    logProtocolSupportEnabled(enable);
> }
>
> --
> Nikolai V. Christensen, Computer Engineer,
> Simulation and Training department
> IFAD TS A/S, Østre stationsvej 43 2.tv, DK-5000 Odense C
> Denmark, EU
> Phone: +45 63 11 02 11  Fax: +45 65 93 29 99
> WWWeb: http://www.ifad.dk
> e-mail: Nikolai.V.Christensen at ifad.dk
> --
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>



More information about the Concurrency-interest mailing list