mirror of https://github.com/apache/cloudstack.git
697 lines
24 KiB
HTML
Executable File
697 lines
24 KiB
HTML
Executable File
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<!--NewPage-->
|
|
<HTML>
|
|
<HEAD>
|
|
<!-- Generated by javadoc (build 1.5.0_13) on Sun Jul 13 13:05:40 EST 2008 -->
|
|
<TITLE>
|
|
Sync (ehcache)
|
|
</TITLE>
|
|
|
|
<META NAME="keywords" CONTENT="net.sf.ehcache.constructs.concurrent.Sync interface">
|
|
|
|
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style">
|
|
|
|
<SCRIPT type="text/javascript">
|
|
function windowTitle()
|
|
{
|
|
parent.document.title="Sync (ehcache)";
|
|
}
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
</NOSCRIPT>
|
|
|
|
</HEAD>
|
|
|
|
<BODY BGCOLOR="white" onload="windowTitle();">
|
|
|
|
|
|
<!-- ========= START OF TOP NAVBAR ======= -->
|
|
<A NAME="navbar_top"><!-- --></A>
|
|
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_top_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Sync.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
<a href="/" target="_top">ehcache</a></EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Mutex.html" title="class in net.sf.ehcache.constructs.concurrent"><B>PREV CLASS</B></A>
|
|
NEXT CLASS</FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../../index.html?net/sf/ehcache/constructs/concurrent/Sync.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="Sync.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_top"></A>
|
|
<!-- ========= END OF TOP NAVBAR ========= -->
|
|
|
|
<HR>
|
|
<!-- ======== START OF CLASS DATA ======== -->
|
|
<H2>
|
|
<FONT SIZE="-1">
|
|
net.sf.ehcache.constructs.concurrent</FONT>
|
|
<BR>
|
|
Interface Sync</H2>
|
|
<DL>
|
|
<DT><B>All Known Implementing Classes:</B> <DD><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Mutex.html" title="class in net.sf.ehcache.constructs.concurrent">Mutex</A></DD>
|
|
</DL>
|
|
<HR>
|
|
<DL>
|
|
<DT><PRE>public interface <B>Sync</B></DL>
|
|
</PRE>
|
|
|
|
<P>
|
|
<DL>
|
|
<DT><B>Version:</B></DT>
|
|
<DD>$Id: Sync.java 519 2007-07-27 07:11:45Z gregluck $</DD>
|
|
<DT><B>Author:</B></DT>
|
|
<DD>Doug Lea
|
|
Main interface for locks, gates, and conditions.
|
|
<p/>
|
|
Sync objects isolate waiting and notification for particular
|
|
logical states, resource availability, events, and the like that are
|
|
shared across multiple threads. Use of Syncs sometimes
|
|
(but by no means always) adds flexibility and efficiency
|
|
compared to the use of plain java monitor methods
|
|
and locking, and are sometimes (but by no means always)
|
|
simpler to program with.
|
|
<p/>
|
|
<p/>
|
|
Most Syncs are intended to be used primarily (although
|
|
not exclusively) in before/after constructions such as:
|
|
<pre>
|
|
class X {
|
|
Sync gate;
|
|
// ...
|
|
<p/>
|
|
public void m() {
|
|
try {
|
|
gate.acquire(); // block until condition holds
|
|
try {
|
|
// ... method body
|
|
}
|
|
finally {
|
|
gate.release()
|
|
}
|
|
}
|
|
catch (InterruptedException ex) {
|
|
// ... evasive action
|
|
}
|
|
}
|
|
<p/>
|
|
public void m2(Sync cond) { // use supplied condition
|
|
try {
|
|
if (cond.attempt(10)) { // try the condition for 10 ms
|
|
try {
|
|
// ... method body
|
|
}
|
|
finally {
|
|
cond.release()
|
|
}
|
|
}
|
|
}
|
|
catch (InterruptedException ex) {
|
|
// ... evasive action
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
Syncs may be used in somewhat tedious but more flexible replacements
|
|
for built-in Java synchronized blocks. For example:
|
|
<pre>
|
|
class HandSynched {
|
|
private double state_ = 0.0;
|
|
private final Sync lock; // use lock type supplied in constructor
|
|
public HandSynched(Sync l) { lock = l; }
|
|
<p/>
|
|
public void changeState(double d) {
|
|
try {
|
|
lock.acquire();
|
|
try { state_ = updateFunction(d); }
|
|
finally { lock.release(); }
|
|
}
|
|
catch(InterruptedException ex) { }
|
|
}
|
|
<p/>
|
|
public double getState() {
|
|
double d = 0.0;
|
|
try {
|
|
lock.acquire();
|
|
try { d = accessFunction(state_); }
|
|
finally { lock.release(); }
|
|
}
|
|
catch(InterruptedException ex){}
|
|
return d;
|
|
}
|
|
private double updateFunction(double d) { ... }
|
|
private double accessFunction(double d) { ... }
|
|
}
|
|
</pre>
|
|
If you have a lot of such methods, and they take a common
|
|
form, you can standardize this using wrappers. Some of these
|
|
wrappers are standardized in LockedExecutor, but you can make others.
|
|
For example:
|
|
<pre>
|
|
class HandSynchedV2 {
|
|
private double state_ = 0.0;
|
|
private final Sync lock; // use lock type supplied in constructor
|
|
public HandSynchedV2(Sync l) { lock = l; }
|
|
<p/>
|
|
protected void runSafely(Runnable r) {
|
|
try {
|
|
lock.acquire();
|
|
try { r.run(); }
|
|
finally { lock.release(); }
|
|
}
|
|
catch (InterruptedException ex) { // propagate without throwing
|
|
Thread.currentThread().interrupt();
|
|
}
|
|
}
|
|
<p/>
|
|
public void changeState(double d) {
|
|
runSafely(new Runnable() {
|
|
public void run() { state_ = updateFunction(d); }
|
|
});
|
|
}
|
|
// ...
|
|
}
|
|
</pre>
|
|
<p/>
|
|
One reason to bother with such constructions is to use deadlock-
|
|
avoiding back-offs when dealing with locks involving multiple objects.
|
|
For example, here is a Cell class that uses attempt to back-off
|
|
and retry if two Cells are trying to swap values with each other
|
|
at the same time.
|
|
<pre>
|
|
class Cell {
|
|
long value;
|
|
Sync lock = ... // some sync implementation class
|
|
void swapValue(Cell other) {
|
|
for (;;) {
|
|
try {
|
|
lock.acquire();
|
|
try {
|
|
if (other.lock.attempt(100)) {
|
|
try {
|
|
long t = value;
|
|
value = other.value;
|
|
other.value = t;
|
|
return;
|
|
}
|
|
finally { other.lock.release(); }
|
|
}
|
|
}
|
|
finally { lock.release(); }
|
|
}
|
|
catch (InterruptedException ex) { return; }
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
<p/>
|
|
Here is an even fancier version, that uses lock re-ordering
|
|
upon conflict:
|
|
<pre>
|
|
class Cell {
|
|
long value;
|
|
Sync lock = ...;
|
|
private static boolean trySwap(Cell a, Cell b) {
|
|
a.lock.acquire();
|
|
try {
|
|
if (!b.lock.attempt(0))
|
|
return false;
|
|
try {
|
|
long t = a.value;
|
|
a.value = b.value;
|
|
b.value = t;
|
|
return true;
|
|
}
|
|
finally { other.lock.release(); }
|
|
}
|
|
finally { lock.release(); }
|
|
return false;
|
|
}
|
|
<p/>
|
|
void swapValue(Cell other) {
|
|
try {
|
|
while (!trySwap(this, other) &&
|
|
!tryswap(other, this))
|
|
Thread.sleep(1);
|
|
}
|
|
catch (InterruptedException ex) { return; }
|
|
}
|
|
}
|
|
</pre>
|
|
<p/>
|
|
Interruptions are in general handled as early as possible.
|
|
Normally, InterruptionExceptions are thrown
|
|
in acquire and attempt(msec) if interruption
|
|
is detected upon entry to the method, as well as in any
|
|
later context surrounding waits.
|
|
However, interruption status is ignored in release();
|
|
<p/>
|
|
Timed versions of attempt report failure via return value.
|
|
If so desired, you can transform such constructions to use exception
|
|
throws via
|
|
<pre>
|
|
if (!c.attempt(timeval)) throw new TimeoutException(timeval);
|
|
</pre>
|
|
<p/>
|
|
The TimoutSync wrapper class can be used to automate such usages.
|
|
<p/>
|
|
All time values are expressed in milliseconds as longs, which have a maximum
|
|
value of Long.MAX_VALUE, or almost 300,000 centuries. It is not
|
|
known whether JVMs actually deal correctly with such extreme values.
|
|
For convenience, some useful time values are defined as static constants.
|
|
<p/>
|
|
All implementations of the three Sync methods guarantee to
|
|
somehow employ Java <code>synchronized</code> methods or blocks,
|
|
and so entail the memory operations described in JLS
|
|
chapter 17 which ensure that variables are loaded and flushed
|
|
within before/after constructions.
|
|
<p/>
|
|
Syncs may also be used in spinlock constructions. Although
|
|
it is normally best to just use acquire(), various forms
|
|
of busy waits can be implemented. For a simple example
|
|
(but one that would probably never be preferable to using acquire()):
|
|
<pre>
|
|
class X {
|
|
Sync lock = ...
|
|
void spinUntilAcquired() throws InterruptedException {
|
|
// Two phase.
|
|
// First spin without pausing.
|
|
int purespins = 10;
|
|
for (int i = 0; i < purespins; ++i) {
|
|
if (lock.attempt(0))
|
|
return true;
|
|
}
|
|
// Second phase - use timed waits
|
|
long waitTime = 1; // 1 millisecond
|
|
for (;;) {
|
|
if (lock.attempt(waitTime))
|
|
return true;
|
|
else
|
|
waitTime = waitTime * 3 / 2 + 1; // increase 50%
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
<p/>
|
|
In addition pure synchronization control, Syncs
|
|
may be useful in any context requiring before/after methods.
|
|
For example, you can use an ObservableSync
|
|
(perhaps as part of a LayeredSync) in order to obtain callbacks
|
|
before and after each method invocation for a given class.
|
|
<p/>
|
|
<p/>
|
|
<p>[<a href="http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html"> Introduction to this package. </a>]</DD>
|
|
</DL>
|
|
<HR>
|
|
|
|
<P>
|
|
<!-- =========== FIELD SUMMARY =========== -->
|
|
|
|
<A NAME="field_summary"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
|
<B>Field Summary</B></FONT></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_CENTURY">ONE_CENTURY</A></B></CODE>
|
|
|
|
<BR>
|
|
One century in milliseconds; convenient as a time-out value</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_DAY">ONE_DAY</A></B></CODE>
|
|
|
|
<BR>
|
|
One day, in milliseconds; convenient as a time-out value *</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_HOUR">ONE_HOUR</A></B></CODE>
|
|
|
|
<BR>
|
|
One hour, in milliseconds; convenient as a time-out value *</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_MINUTE">ONE_MINUTE</A></B></CODE>
|
|
|
|
<BR>
|
|
One minute, in milliseconds; convenient as a time-out value *</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_SECOND">ONE_SECOND</A></B></CODE>
|
|
|
|
<BR>
|
|
One second, in milliseconds; convenient as a time-out value *</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_WEEK">ONE_WEEK</A></B></CODE>
|
|
|
|
<BR>
|
|
One week, in milliseconds; convenient as a time-out value *</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE>static long</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#ONE_YEAR">ONE_YEAR</A></B></CODE>
|
|
|
|
<BR>
|
|
One year in milliseconds; convenient as a time-out value
|
|
Not that it matters, but there is some variation across
|
|
standard sources about value at msec precision.</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<!-- ========== METHOD SUMMARY =========== -->
|
|
|
|
<A NAME="method_summary"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
|
|
<B>Method Summary</B></FONT></TH>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE> void</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#acquire()">acquire</A></B>()</CODE>
|
|
|
|
<BR>
|
|
Wait (possibly forever) until successful passage.</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE> boolean</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#attempt(long)">attempt</A></B>(long msecs)</CODE>
|
|
|
|
<BR>
|
|
Wait at most msecs to pass; report whether passed.</TD>
|
|
</TR>
|
|
<TR BGCOLOR="white" CLASS="TableRowColor">
|
|
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
|
|
<CODE> void</CODE></FONT></TD>
|
|
<TD><CODE><B><A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Sync.html#release()">release</A></B>()</CODE>
|
|
|
|
<BR>
|
|
Potentially enable others to pass.</TD>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
|
|
<!-- ============ FIELD DETAIL =========== -->
|
|
|
|
<A NAME="field_detail"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
<B>Field Detail</B></FONT></TH>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="ONE_SECOND"><!-- --></A><H3>
|
|
ONE_SECOND</H3>
|
|
<PRE>
|
|
static final long <B>ONE_SECOND</B></PRE>
|
|
<DL>
|
|
<DD>One second, in milliseconds; convenient as a time-out value *
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_SECOND">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_MINUTE"><!-- --></A><H3>
|
|
ONE_MINUTE</H3>
|
|
<PRE>
|
|
static final long <B>ONE_MINUTE</B></PRE>
|
|
<DL>
|
|
<DD>One minute, in milliseconds; convenient as a time-out value *
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_MINUTE">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_HOUR"><!-- --></A><H3>
|
|
ONE_HOUR</H3>
|
|
<PRE>
|
|
static final long <B>ONE_HOUR</B></PRE>
|
|
<DL>
|
|
<DD>One hour, in milliseconds; convenient as a time-out value *
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_HOUR">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_DAY"><!-- --></A><H3>
|
|
ONE_DAY</H3>
|
|
<PRE>
|
|
static final long <B>ONE_DAY</B></PRE>
|
|
<DL>
|
|
<DD>One day, in milliseconds; convenient as a time-out value *
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_DAY">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_WEEK"><!-- --></A><H3>
|
|
ONE_WEEK</H3>
|
|
<PRE>
|
|
static final long <B>ONE_WEEK</B></PRE>
|
|
<DL>
|
|
<DD>One week, in milliseconds; convenient as a time-out value *
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_WEEK">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_YEAR"><!-- --></A><H3>
|
|
ONE_YEAR</H3>
|
|
<PRE>
|
|
static final long <B>ONE_YEAR</B></PRE>
|
|
<DL>
|
|
<DD>One year in milliseconds; convenient as a time-out value
|
|
Not that it matters, but there is some variation across
|
|
standard sources about value at msec precision.
|
|
The value used is the same as in java.util.GregorianCalendar
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_YEAR">Constant Field Values</A></DL>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="ONE_CENTURY"><!-- --></A><H3>
|
|
ONE_CENTURY</H3>
|
|
<PRE>
|
|
static final long <B>ONE_CENTURY</B></PRE>
|
|
<DL>
|
|
<DD>One century in milliseconds; convenient as a time-out value
|
|
<P>
|
|
<DL>
|
|
<DT><B>See Also:</B><DD><A HREF="../../../../../constant-values.html#net.sf.ehcache.constructs.concurrent.Sync.ONE_CENTURY">Constant Field Values</A></DL>
|
|
</DL>
|
|
|
|
<!-- ============ METHOD DETAIL ========== -->
|
|
|
|
<A NAME="method_detail"><!-- --></A>
|
|
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
|
|
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
|
|
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
|
|
<B>Method Detail</B></FONT></TH>
|
|
</TR>
|
|
</TABLE>
|
|
|
|
<A NAME="acquire()"><!-- --></A><H3>
|
|
acquire</H3>
|
|
<PRE>
|
|
void <B>acquire</B>()
|
|
throws java.lang.InterruptedException</PRE>
|
|
<DL>
|
|
<DD>Wait (possibly forever) until successful passage.
|
|
Fail only upon interuption. Interruptions always result in
|
|
`clean' failures. On failure, you can be sure that it has not
|
|
been acquired, and that no
|
|
corresponding release should be performed. Conversely,
|
|
a normal return guarantees that the acquire was successful.
|
|
<P>
|
|
<DD><DL>
|
|
|
|
<DT><B>Throws:</B>
|
|
<DD><CODE>java.lang.InterruptedException</CODE></DL>
|
|
</DD>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="attempt(long)"><!-- --></A><H3>
|
|
attempt</H3>
|
|
<PRE>
|
|
boolean <B>attempt</B>(long msecs)
|
|
throws java.lang.InterruptedException</PRE>
|
|
<DL>
|
|
<DD>Wait at most msecs to pass; report whether passed.
|
|
<p/>
|
|
The method has best-effort semantics:
|
|
The msecs bound cannot
|
|
be guaranteed to be a precise upper bound on wait time in Java.
|
|
Implementations generally can only attempt to return as soon as possible
|
|
after the specified bound. Also, timers in Java do not stop during garbage
|
|
collection, so timeouts can occur just because a GC intervened.
|
|
So, msecs arguments should be used in
|
|
a coarse-grained manner. Further,
|
|
implementations cannot always guarantee that this method
|
|
will return at all without blocking indefinitely when used in
|
|
unintended ways. For example, deadlocks may be encountered
|
|
when called in an unintended context.
|
|
<p/>
|
|
<P>
|
|
<DD><DL>
|
|
<DT><B>Parameters:</B><DD><CODE>msecs</CODE> - the number of milleseconds to wait.
|
|
An argument less than or equal to zero means not to wait at all.
|
|
However, this may still require
|
|
access to a synchronization lock, which can impose unbounded
|
|
delay if there is a lot of contention among threads.
|
|
<DT><B>Returns:</B><DD>true if acquired
|
|
<DT><B>Throws:</B>
|
|
<DD><CODE>java.lang.InterruptedException</CODE></DL>
|
|
</DD>
|
|
</DL>
|
|
<HR>
|
|
|
|
<A NAME="release()"><!-- --></A><H3>
|
|
release</H3>
|
|
<PRE>
|
|
void <B>release</B>()</PRE>
|
|
<DL>
|
|
<DD>Potentially enable others to pass.
|
|
<p/>
|
|
Because release does not raise exceptions,
|
|
it can be used in `finally' clauses without requiring extra
|
|
embedded try/catch blocks. But keep in mind that
|
|
as with any java method, implementations may
|
|
still throw unchecked exceptions such as Error or NullPointerException
|
|
when faced with uncontinuable errors. However, these should normally
|
|
only be caught by higher-level error handlers.
|
|
<P>
|
|
<DD><DL>
|
|
</DL>
|
|
</DD>
|
|
</DL>
|
|
<!-- ========= END OF CLASS DATA ========= -->
|
|
<HR>
|
|
|
|
|
|
<!-- ======= START OF BOTTOM NAVBAR ====== -->
|
|
<A NAME="navbar_bottom"><!-- --></A>
|
|
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
|
|
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
|
|
<TR>
|
|
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
|
|
<A NAME="navbar_bottom_firstrow"><!-- --></A>
|
|
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
|
|
<TR ALIGN="center" VALIGN="top">
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Sync.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
|
|
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
|
|
</TR>
|
|
</TABLE>
|
|
</TD>
|
|
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
|
|
<a href="/" target="_top">ehcache</a></EM>
|
|
</TD>
|
|
</TR>
|
|
|
|
<TR>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../../net/sf/ehcache/constructs/concurrent/Mutex.html" title="class in net.sf.ehcache.constructs.concurrent"><B>PREV CLASS</B></A>
|
|
NEXT CLASS</FONT></TD>
|
|
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
|
|
<A HREF="../../../../../index.html?net/sf/ehcache/constructs/concurrent/Sync.html" target="_top"><B>FRAMES</B></A>
|
|
<A HREF="Sync.html" target="_top"><B>NO FRAMES</B></A>
|
|
<SCRIPT type="text/javascript">
|
|
<!--
|
|
if(window==top) {
|
|
document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>');
|
|
}
|
|
//-->
|
|
</SCRIPT>
|
|
<NOSCRIPT>
|
|
<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>
|
|
</NOSCRIPT>
|
|
|
|
|
|
</FONT></TD>
|
|
</TR>
|
|
<TR>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
|
|
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
|
|
DETAIL: <A HREF="#field_detail">FIELD</A> | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
|
|
</TR>
|
|
</TABLE>
|
|
<A NAME="skip-navbar_bottom"></A>
|
|
<!-- ======== END OF BOTTOM NAVBAR ======= -->
|
|
|
|
<HR>
|
|
|
|
</BODY>
|
|
</HTML>
|