From 64216d3ea9ba04ee54a6a33f3074d59f55a6e0ef Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sat, 18 Jul 2009 02:59:32 +0200 Subject: Added feedback from r.spilker. --- website/features/Synchronized.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'website/features') diff --git a/website/features/Synchronized.html b/website/features/Synchronized.html index 643b0cd3..e3059655 100644 --- a/website/features/Synchronized.html +++ b/website/features/Synchronized.html @@ -23,8 +23,8 @@ named $LOCK instead.

If you want, you can create these locks yourself. The $lock and $LOCK fields will of course not be generated if you - already created them yourself. You can also choose to lock on another field, by using specifying it as parameter to the @Synchronized - annotation. In this usage variant, the fields will not be created automatically, and you must explicitly create them yourself. + already created them yourself. You can also choose to lock on another field, by specifying it as parameter to the @Synchronized + annotation. In this usage variant, the fields will not be created automatically, and you must explicitly create them yourself, or an error will be emitted.

Locking on this or your own class object can have unfortunate side-effects, as other code not under your control can lock on these objects as well, which can cause race conditions and other nasty threading-related bugs. @@ -48,6 +48,9 @@ If $lock and/or $LOCK are auto-generated, the fields are initialized with an empty Object[] array, and not just a new Object() as most snippets showing this pattern in action use. Lombok does this because a new object is NOT serializable, but 0-size array is. Therefore, using @Synchronized will not prevent your object from being serialized. +

+ If you'd like to know why a field is not automatically generated when you choose your own name for the lock object: Because otherwise making a typo + in the field name will result in a very hard to find bug!

-- cgit