blob: d89764408aab7c03a54bf4f4d44dba53a78e2263 [file] [log] [blame]
<!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_06) on Mon Nov 20 18:18:41 PST 2006 -->
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<TITLE>
Lock (OpenJPA 0.9.6-incubating API)
</TITLE>
<META NAME="keywords" CONTENT="org.apache.openjpa.lib.util.concurrent.Lock interface">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
parent.document.title="Lock (OpenJPA 0.9.6-incubating API)";
}
</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>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Lock.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/CopyOnWriteArraySet.html" title="class in org.apache.openjpa.lib.util.concurrent"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/NanoTimer.html" title="interface in org.apache.openjpa.lib.util.concurrent"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../../index.html?org/apache/openjpa/lib/util/concurrent/Lock.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="Lock.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<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:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<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">
org.apache.openjpa.lib.util.concurrent</FONT>
<BR>
Interface Lock</H2>
<DL>
<DT><B>All Known Implementing Classes:</B> <DD><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/ReentrantLock.html" title="class in org.apache.openjpa.lib.util.concurrent">ReentrantLock</A></DD>
</DL>
<HR>
<DL>
<DT><PRE>public interface <B>Lock</B></DL>
</PRE>
<P>
<tt>Lock</tt> implementations provide more extensive locking
operations than can be obtained using <tt>synchronized</tt> methods
and statements. They allow more flexible structuring, may have
quite different properties, and may support multiple associated
<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A> objects.
A lock is a tool for controlling access to a shared resource by
multiple threads. Commonly, a lock provides exclusive access to a
shared resource: only one thread at a time can acquire the lock and
all access to the shared resource requires that the lock be
acquired first. However, some locks may allow concurrent access to
a shared resource, such as the read lock of a <CODE>ReadWriteLock</CODE>.
The use of <tt>synchronized</tt> methods or statements provides
access to the implicit monitor lock associated with every object, but
forces all lock acquisition and release to occur in a block-structured way:
when multiple locks are acquired they must be released in the opposite
order, and all locks must be released in the same lexical scope in which
they were acquired.
While the scoping mechanism for <tt>synchronized</tt> methods
and statements makes it much easier to program with monitor locks,
and helps avoid many common programming errors involving locks,
there are occasions where you need to work with locks in a more
flexible way. For example, some algorithms for traversing
concurrently accessed data structures require the use of
&quot;hand-over-hand&quot; or &quot;chain locking&quot;: you
acquire the lock of node A, then node B, then release A and acquire
C, then release B and acquire D and so on. Implementations of the
<tt>Lock</tt> interface enable the use of such techniques by
allowing a lock to be acquired and released in different scopes,
and allowing multiple locks to be acquired and released in any order.
With this increased flexibility comes additional
responsibility. The absence of block-structured locking removes the
automatic release of locks that occurs with <tt>synchronized</tt>
methods and statements. In most cases, the following idiom should be used:
<pre><tt> Lock l = ...; l.lock(); try {
// access the resource protected by this lock } finally { l.unlock(); }
</tt></pre>
When locking and unlocking occur in different scopes, care must be
taken to ensure that all code that is executed while the lock is
held is protected by try-finally or try-catch to ensure that the
lock is released when necessary.
<tt>Lock</tt> implementations provide additional functionality
over the use of <tt>synchronized</tt> methods and statements by
providing a non-blocking attempt to acquire a lock(<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#tryLock()"><CODE>tryLock()</CODE></A>), an attempt to acquire the lock that can be
interrupted(<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#lockInterruptibly()"><CODE>lockInterruptibly()</CODE></A>, and an attempt to acquire
the lock that can timeout(<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#tryLock(long, org.apache.openjpa.lib.util.concurrent.TimeUnit)"><CODE>tryLock(long, TimeUnit)</CODE></A>).
A <tt>Lock</tt> class can also provide behavior and semantics
that is quite different from that of the implicit monitor lock,
such as guaranteed ordering, non-reentrant usage, or deadlock
detection. If an implementation provides such specialized semantics
then the implementation must document those semantics.
Note that <tt>Lock</tt> instances are just normal objects and can
themselves be used as the target in a <tt>synchronized</tt> statement.
Acquiring the
monitor lock of a <tt>Lock</tt> instance has no specified relationship
with invoking any of the <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#lock()"><CODE>lock()</CODE></A> methods of that instance.
It is recommended that to avoid confusion you never use <tt>Lock</tt>
instances in this way, except within their own implementation.
Except where noted, passing a <tt>null</tt> value for any
parameter will result in a <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/NullPointerException.html" title="class or interface in java.lang"><CODE>NullPointerException</CODE></A> being thrown.
<h3>Memory Synchronization</h3>
All <tt>Lock</tt> implementations <em>must</em> enforce the same
memory synchronization semantics as provided by the built-in monitor
lock, as described in <a href="http://java.sun.com/docs/books/jls/">
The Java Language Specification, Third Edition(17.4 Memory Model)</a>:
<ul>
<li>A successful <tt>lock</tt> operation has the same memory
synchronization effects as a successful <em>Lock</em> action.
<li>A successful <tt>unlock</tt> operation has the same
memory synchronization effects as a successful <em>Unlock</em> action.
</ul> Unsuccessful locking and unlocking operations, and reentrant
locking/unlocking operations, do not require any memory
synchronization effects.
<h3>Implementation Considerations</h3>
The three forms of lock acquisition(interruptible,
non-interruptible, and timed) may differ in their performance
characteristics, ordering guarantees, or other implementation
qualities. Further, the ability to interrupt the <em>ongoing</em>
acquisition of a lock may not be available in a given <tt>Lock</tt>
class. Consequently, an implementation is not required to define
exactly the same guarantees or semantics for all three forms of
lock acquisition, nor is it required to support interruption of an
ongoing lock acquisition. An implementation is required to clearly
document the semantics and guarantees provided by each of the
locking methods. It must also obey the interruption semantics as
defined in this interface, to the extent that interruption of lock
acquisition is supported: which is either totally, or only on method entry.
As interruption generally implies cancellation, and checks for
interruption are often infrequent, an implementation can favor responding
to an interrupt over normal method return. This is true even if it can be
shown that the interrupt occurred after another action may have unblocked
the thread. An implementation should document this behavior.
<P>
<P>
<DL>
<DT><B>Since:</B></DT>
<DD>1.5</DD>
<DT><B>Author:</B></DT>
<DD>Doug Lea</DD>
<DT><B>See Also:</B><DD><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/ReentrantLock.html" title="class in org.apache.openjpa.lib.util.concurrent"><CODE>ReentrantLock</CODE></A>,
<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A>,
<CODE>ReadWriteLock</CODE></DL>
<HR>
<P>
<!-- ========== 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>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#lock()">lock</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Acquires the lock.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#lockInterruptibly()">lockInterruptibly</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Acquires the lock unless the current thread is
<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent">Condition</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#newCondition()">newCondition</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Returns a new <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A> instance that is bound to this
<tt>Lock</tt> instance.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#tryLock()">tryLock</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Acquires the lock only if it is free at the time of invocation.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;boolean</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#tryLock(long, org.apache.openjpa.lib.util.concurrent.TimeUnit)">tryLock</A></B>(long&nbsp;time,
<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/TimeUnit.html" title="class in org.apache.openjpa.lib.util.concurrent">TimeUnit</A>&nbsp;unit)</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Acquires the lock if it is free within the given waiting time and the
current thread has not been <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>&nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Lock.html#unlock()">unlock</A></B>()</CODE>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Releases the lock.</TD>
</TR>
</TABLE>
&nbsp;
<P>
<!-- ============ 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="lock()"><!-- --></A><H3>
lock</H3>
<PRE>
void <B>lock</B>()</PRE>
<DL>
<DD>Acquires the lock. If the lock is not available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until the lock has been acquired.
<b>Implementation Considerations</b>
A <tt>Lock</tt> implementation may be able to detect
erroneous use of the lock, such as an invocation that would cause
deadlock, and may throw an(unchecked) exception in such circumstances.
The circumstances and the exception type must be documented by that
<tt>Lock</tt> implementation.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="lockInterruptibly()"><!-- --></A><H3>
lockInterruptibly</H3>
<PRE>
void <B>lockInterruptibly</B>()
throws <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang">InterruptedException</A></PRE>
<DL>
<DD>Acquires the lock unless the current thread is
<A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A>.
Acquires the lock if it is available and returns immediately.
If the lock is not available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until one of two things happens:
<ul>
<li>The lock is acquired by the current thread; or
<li>Some other thread <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupts</CODE></A> the current
thread, and interruption of lock acquisition is supported.
</ul> If the current thread:
<ul>
<li>has its interrupted status set on entry to this method; or
<li>is <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A> while acquiring
the lock, and interruption of lock acquisition is supported,
</ul>
then <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang"><CODE>InterruptedException</CODE></A> is thrown and the current thread's
interrupted status is cleared.
<b>Implementation Considerations</b>
The ability to interrupt a lock acquisition in some
implementations may not be possible, and if possible may be an
expensive operation. The programmer should be aware that this
may be the case. An implementation should document when this is the case.
An implementation can favor responding to an interrupt over
normal method return.
A <tt>Lock</tt> implementation may be able to detect
erroneous use of the lock, such as an invocation that would
cause deadlock, and may throw an(unchecked) exception in such
circumstances. The circumstances and the exception type must
be documented by that <tt>Lock</tt> implementation.
<P>
<DD><DL>
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang">InterruptedException</A></CODE> - if the current thread is interrupted
while acquiring the lock(and interruption of lock acquisition is
supported).<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>Thread.interrupt()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="tryLock()"><!-- --></A><H3>
tryLock</H3>
<PRE>
boolean <B>tryLock</B>()</PRE>
<DL>
<DD>Acquires the lock only if it is free at the time of invocation.
Acquires the lock if it is available and returns immediately
with the value <tt>true</tt>.
If the lock is not available then this method will return
immediately with the value <tt>false</tt>.
A typical usage idiom for this method would be:
<pre> Lock lock = ...; if (lock.tryLock()) { try {
// manipulate protected state } finally { lock.unlock(); } } else {
// perform alternative actions }
</pre>
This usage ensures that the lock is unlocked if it was acquired, and
doesn't try to unlock if the lock was not acquired.
<P>
<DD><DL>
<DT><B>Returns:</B><DD><tt>true</tt> if the lock was acquired and <tt>false</tt>
otherwise.</DL>
</DD>
</DL>
<HR>
<A NAME="tryLock(long, org.apache.openjpa.lib.util.concurrent.TimeUnit)"><!-- --></A><H3>
tryLock</H3>
<PRE>
boolean <B>tryLock</B>(long&nbsp;time,
<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/TimeUnit.html" title="class in org.apache.openjpa.lib.util.concurrent">TimeUnit</A>&nbsp;unit)
throws <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang">InterruptedException</A></PRE>
<DL>
<DD>Acquires the lock if it is free within the given waiting time and the
current thread has not been <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A>.
If the lock is available this method returns immediately
with the value <tt>true</tt>. If the lock is not available then
the current thread becomes disabled for thread scheduling
purposes and lies dormant until one of three things happens:
<ul>
<li>The lock is acquired by the current thread; or
<li>Some other thread <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupts</CODE></A> the current
thread, and interruption of lock acquisition is supported; or
<li>The specified waiting time elapses
</ul> If the lock is acquired then the value <tt>true</tt> is returned.
If the current thread:
<ul>
<li>has its interrupted status set on entry to this method; or
<li>is <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>interrupted</CODE></A> while acquiring
the lock, and interruption of lock acquisition is supported,
</ul>
then <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang"><CODE>InterruptedException</CODE></A> is thrown and the current thread's
interrupted status is cleared.
If the specified waiting time elapses then the value <tt>false</tt>
is returned. If the time is
less than or equal to zero, the method will not wait at all.
<b>Implementation Considerations</b>
The ability to interrupt a lock acquisition in some implementations
may not be possible, and if possible may be an expensive operation.
The programmer should be aware that this may be the case. An
implementation should document when this is the case.
An implementation can favor responding to an interrupt over normal
method return, or reporting a timeout.
A <tt>Lock</tt> implementation may be able to detect
erroneous use of the lock, such as an invocation that would cause
deadlock, and may throw an(unchecked) exception in such circumstances.
The circumstances and the exception type must be documented by that
<tt>Lock</tt> implementation.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>time</CODE> - the maximum time to wait for the lock<DD><CODE>unit</CODE> - the time unit of the <tt>time</tt> argument.
<DT><B>Returns:</B><DD><tt>true</tt> if the lock was acquired and <tt>false</tt>
if the waiting time elapsed before the lock was acquired.
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InterruptedException.html" title="class or interface in java.lang">InterruptedException</A></CODE> - if the current thread is interrupted
while acquiring the lock(and interruption of lock acquisition is
supported).<DT><B>See Also:</B><DD><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Thread.html#interrupt()" title="class or interface in java.lang"><CODE>Thread.interrupt()</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="unlock()"><!-- --></A><H3>
unlock</H3>
<PRE>
void <B>unlock</B>()</PRE>
<DL>
<DD>Releases the lock.
<b>Implementation Considerations</b>
A <tt>Lock</tt> implementation will usually impose
restrictions on which thread can release a lock(typically only the
holder of the lock can release it) and may throw
an(unchecked) exception if the restriction is violated.
Any restrictions and the exception
type must be documented by that <tt>Lock</tt> implementation.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="newCondition()"><!-- --></A><H3>
newCondition</H3>
<PRE>
<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent">Condition</A> <B>newCondition</B>()</PRE>
<DL>
<DD>Returns a new <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A> instance that is bound to this
<tt>Lock</tt> instance.
Before waiting on the condition the lock must be held by the
current thread.
A call to <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html#await()"><CODE>Condition.await()</CODE></A> will atomically release the lock
before waiting and re-acquire the lock before the wait returns.
<b>Implementation Considerations</b>
The exact operation of the <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A> instance depends on the
<tt>Lock</tt> implementation and must be documented by that
implementation.
<P>
<DD><DL>
<DT><B>Returns:</B><DD>A new <A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/Condition.html" title="interface in org.apache.openjpa.lib.util.concurrent"><CODE>Condition</CODE></A> instance for this <tt>Lock</tt> instance.
<DT><B>Throws:</B>
<DD><CODE><A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/UnsupportedOperationException.html" title="class or interface in java.lang">UnsupportedOperationException</A></CODE> - if this <tt>Lock</tt>
implementation does not support conditions.</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>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/Lock.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
&nbsp;<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/CopyOnWriteArraySet.html" title="class in org.apache.openjpa.lib.util.concurrent"><B>PREV CLASS</B></A>&nbsp;
&nbsp;<A HREF="../../../../../../org/apache/openjpa/lib/util/concurrent/NanoTimer.html" title="interface in org.apache.openjpa.lib.util.concurrent"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../../../../index.html?org/apache/openjpa/lib/util/concurrent/Lock.html" target="_top"><B>FRAMES</B></A> &nbsp;
&nbsp;<A HREF="Lock.html" target="_top"><B>NO FRAMES</B></A> &nbsp;
&nbsp;<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:&nbsp;NESTED&nbsp;|&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL:&nbsp;FIELD&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
Copyright &copy; 2006 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.
</BODY>
</HTML>