From bc35f73ae80802ab6758509481dacd66c5dc3285 Mon Sep 17 00:00:00 2001 From: Reinier Zwitserloot Date: Sat, 18 Jul 2009 02:28:29 +0200 Subject: Added text for the Synchronized annotation to the features pages. Also did some fixes in regards to whitespacing (some fancy footwork in regards to white-space: pre). --- website/features/Synchronized.html | 60 ++++++++++++++++++++++++++++++++++++++ website/features/features.css | 12 ++++---- 2 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 website/features/Synchronized.html (limited to 'website/features') diff --git a/website/features/Synchronized.html b/website/features/Synchronized.html new file mode 100644 index 00000000..643b0cd3 --- /dev/null +++ b/website/features/Synchronized.html @@ -0,0 +1,60 @@ + + + + + + + + @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 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. +

+ 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@
+
+
+
+
+

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

+
+
+ +
+
+
diff --git a/website/features/features.css b/website/features/features.css index 7edaf769..d726f679 100644 --- a/website/features/features.css +++ b/website/features/features.css @@ -78,11 +78,10 @@ h1 { } .snippets { - margin-top: 32px; + margin-top: 0px; } .snippets .pre { - white-space: pre; float: left; width: 45%; } @@ -93,6 +92,10 @@ h1 { border: 1px dotted #888; } +.snippet font { + white-space: pre; +} + .snippets .sep { display: block; width: 5%; @@ -101,7 +104,6 @@ h1 { } .snippets .post { - white-space: pre; float: left; width: 45%; } @@ -114,10 +116,6 @@ h1 { font-size: 14px; } -.snippet br { - display: none; -} - .footer { clear: left; margin: 0 auto 0 auto; -- cgit