From 8b7a7cbc813653a3248d6cf3a7779e220957bc85 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Mon, 8 May 2017 21:28:02 +0200 Subject: The great rename: the old ‘website’ is now ‘website-old’, and ‘website2’ is now ‘website’. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- website/features/Synchronized.html | 85 -------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 website/features/Synchronized.html (limited to 'website/features/Synchronized.html') diff --git a/website/features/Synchronized.html b/website/features/Synchronized.html deleted file mode 100644 index b575e47c..00000000 --- a/website/features/Synchronized.html +++ /dev/null @@ -1,85 +0,0 @@ - - - - - - - - @Synchronized -
-
-
- -

@Synchronized

- -
-

Overview

-

- @Synchronized is a safer variant of the synchronized method modifier. Like synchronized, the - annotation can be used on static and instance methods only. It operates similarly to the synchronized keyword, but it locks - on different objects. The keyword locks on this, but the annotation locks on a field named $lock, which is private.
- If the field does not exist, it is created for you. If you annotate a static method, the annotation locks on a static field - 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 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. -

-
-
-
-

With Lombok

-
@HTML_PRE@
-
-
-
-

Vanilla Java

-
@HTML_POST@
-
-
-
-
-

Supported configuration keys:

-
-
lombok.synchronized.flagUsage = [warning | error] (default: not set)
-
Lombok will flag any usage of @Synchronized as a warning or error if configured.
-
-
-
-

Small print

-

- 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. -

- Having at least one @Synchronized method in your class means there will be a lock field, but if you later remove all such methods, - there will no longer be a lock field. That means your predetermined serialVersionUID changes. We suggest you always add - a serialVersionUID to your classes if you intend to store them long-term via java's serialization mechanism. If you do so, removing - all @Synchronized annotations from your method will not break serialization. -

- 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