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

This commit is contained in:
Reinier Zwitserloot committed 2009-07-18 02:28:29 +02:00
1 parent 1e369a3aa4
commit bc35f73ae8
5 files changed
+113 -7

No files matched your search

+5
View File
@@ -77,6 +77,9 @@
<antcall target="-integrateSnippet">
<param name="transformationName" value="Cleanup" />
</antcall>
<antcall target="-integrateSnippet">
<param name="transformationName" value="Synchronized" />
</antcall>
<mkdir dir="dist" />
<tar destfile="dist/website.tar">
<tarfileset dir="build/website" />
@@ -100,6 +103,7 @@
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<loadfile property="post" encoding="UTF-8" srcFile="${postout}">
@@ -107,6 +111,7 @@
<linecontainsregexp>
<regexp pattern="(code>)|(font>)" />
</linecontainsregexp>
<striplinebreaks />
</filterchain>
</loadfile>
<delete dir="build/temp" quiet="true" />
@@ -0,0 +1,23 @@
public class SynchronizedExample {
private static final Object $LOCK = new Object[0];
private final Object $lock = new Object[0];
private final Object myLock = new Object();
public static void hello() {
synchronized($LOCK) {
System.out.println("world");
}
}
public int answerToLife() {
synchronized($lock) {
return 42;
}
}
public void foo() {
synchronized(myLock) {
System.out.println("bar");
}
}
}
@@ -0,0 +1,20 @@
import lombok.Synchronized;
public class SynchronizedExample {
private final Object myLock = new Object();
@Synchronized
public static void hello() {
System.out.println("world");
}
@Synchronized
public int answerToLife() {
return 42;
}
@Synchronized("myLock")
public void foo() {
System.out.println("bar");
}
}
+60
View File
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="../logi/reset.css" />
<link rel="stylesheet" type="text/css" href="features.css" />
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta name="description" content="Spice up your java" />
<title>@Synchronized</title>
<!--[if lt IE 7]><script type="text/javascript" src="logi/iepngfix_tilebg.js"></script><![endif]-->
</head><body><div id="pepper">
<div class="minimumHeight"></div>
<div class="meat">
<div class="header"><a href="../index.html">Project Lombok</a></div>
<h1>@Synchronized</h1>
<div class="byline"><code>synchronized</code> done right: Don't expose your locks.</div>
<div class="overview">
<h3>Overview</h3>
<p>
<code>@Synchronized</code> is a safer variant of the <code>synchronized</code> method modifier. Like <code>synchronized</code>, the
annotation can be used on static and instance methods only. It operates similarly to the <code>synchronized</code> keyword, but it locks
on different objects. The keyword locks on <code>this</code>, but the annotation locks on a field named <code>$lock</code>, which is private.<br />
If the field does not exist, it is created for you. If you annotate a <code>static</code> method, the annotation locks on a static field
named <code>$LOCK</code> instead.
</p><p>
If you want, you can create these locks yourself. The <code>$lock</code> and <code>$LOCK</code> 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 <code>@Synchronized</code>
annotation. In this usage variant, the fields will not be created automatically, and you must explicitly create them yourself.
</p><p>
Locking on <code>this</code> 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.
</p>
</div>
<div class="snippets">
<div class="pre">
<h3>With Lombok</h3>
<div class="snippet">@HTML_PRE@</div>
</div>
<div class="sep"></div>
<div class="post">
<h3>Vanilla Java</h3>
<div class="snippet">@HTML_POST@</div>
</div>
</div>
<div style="clear: left;"></div>
<div class="overview">
<h3>Small print</h3><div class="smallprint">
<p>
If <code>$lock</code> and/or <code>$LOCK</code> are auto-generated, the fields are initialized with an empty <code>Object[]</code> array, and not
just a <code>new Object()</code> as most snippets showing this pattern in action use. Lombok does this because a new object is <em>NOT</em>
serializable, but 0-size array is. Therefore, using <code>@Synchronized</code> will not prevent your object from being serialized.
</p>
</div>
</div>
<div class="footer">
<a href="index.html">Back to features</a> | <a href="Cleanup.html">Previous feature (@Cleanup)</a> | <a href="SneakyThrows.html">Next feature (@SneakyThrows)</a><br />
<span class="copyright">Copyright &copy; 2009 Reinier Zwitserloot and Roel Spilker, licensed under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT licence</a>.</span>
</div>
<div style="clear: both;"></div>
</div>
</div></body></html>
+5 -7
View File
@@ -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;