Synchronized classes have no public members
Spacen Jasset via Digitalmars-d
digitalmars-d at puremagic.com
Sat Oct 24 08:05:00 PDT 2015
On Tuesday, 20 October 2015 at 18:15:05 UTC, Bruno Medeiros wrote:
> On 16/10/2015 08:02, Jacob Carlborg wrote:
>> On 2015-10-16 08:49, Dicebot wrote:
>>
>>> As far as I understand topic is about deprecating direct
>>> field access of
>>> synchronized classes, method calls in synhronized classes and
>>> `synchronized () {}` blocks will remain untouched.
>>
>> Is it even possible to do synchronized classes in Java? That
>> is, but
>> synchronized on the class declaration as in D.
>>
>
> No, it's not possible. `synchronized` in Java can only apply to
> methods, or the synchronized statement.
>
> And (for a change), rightly so that it's not possible. This
> synchronized class feature seems to me a clumsy mis-feature. At
> first glance at least.
This change seems like a good idea.
As far as having synchronized classes go. I think they can be
useful. If, as some of the respondents have said a synchronized
class is wrong, then perhaps their classes are too big and indeed
require fine grained locks everywhere. Or, if it is performance
you are after, then that is the way you might do it.
If, however, you would like better defense against multi-threaded
related breakage against your non time-critical class, a class
wide lock, surely, would be of benefit.
More information about the Digitalmars-d
mailing list