Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.thread

public Class AutoLock

extends Object
implements AutoCloseable, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.AutoCloseable
Known Direct Subclasses
org.eclipse.jetty.util.thread.AutoLock.WithCondition
Imports
java.io.Serial, .Serializable, java.util.concurrent.TimeUnit, java.util.concurrent.locks.Condition, .ReentrantLock

Reentrant lock that can be used in a try-with-resources statement.

Typical usage:

try (AutoLock lock = this.lock.lock())
{
    // Something
}

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
AutoLock.WithCondition

A reentrant lock with a condition that can be used in a try-with-resources statement.

Field Summary

Modifier and TypeField and Description
private final ReentrantLock
private static final long

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public boolean
isHeldByCurrentThread()

Returns: whether this lock is held by the current thread

pack-priv boolean
public AutoLock

Returns:

this AutoLock for unlocking
lock
()

Acquires the lock.

public Condition
newCondition()

Returns: a Condition associated with this lock

public AutoLock

Returns:

this AutoLock for unlocking
tryLock
()

Tries to acquire the lock.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_lockback to summary
private final ReentrantLock _lock
serialVersionUIDback to summary
private static final long serialVersionUID
Annotations
@Serial

Constructor Detail

AutoLockback to summary
public AutoLock()

Method Detail

closeback to summary
public void close()

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
isHeldByCurrentThreadback to summary
public boolean isHeldByCurrentThread()
Returns:boolean

whether this lock is held by the current thread

See Also
ReentrantLock#isHeldByCurrentThread()
isLockedback to summary
pack-priv boolean isLocked()
lockback to summary
public AutoLock lock()

Acquires the lock.

Returns:AutoLock

this AutoLock for unlocking

newConditionback to summary
public Condition newCondition()
Returns:Condition

a Condition associated with this lock

tryLockback to summary
public AutoLock tryLock()

Tries to acquire the lock.

Whether the lock was acquired can be tested with isHeldByCurrentThread().

Typical usage of this method is in toString(), to avoid deadlocks when the implementation needs to lock to retrieve a consistent state to produce the string.

Returns:AutoLock

this AutoLock for unlocking

org.eclipse.jetty.util.thread back to summary

public Class AutoLock.WithCondition

extends AutoLock
Class Inheritance

A reentrant lock with a condition that can be used in a try-with-resources statement.

Typical usage:

// Waiting
try (AutoLock lock = _lock.lock())
{
    lock.await();
}

// Signaling
try (AutoLock lock = _lock.lock())
{
    lock.signalAll();
}

Field Summary

Modifier and TypeField and Description
private final Condition

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
await(long
the time to wait
time
,
TimeUnit
the time unit
unit
)

Returns: false if the waiting time elapsed

public AutoLock.WithCondition
lock()

Overrides org.eclipse.jetty.util.thread.AutoLock.lock.

Acquires the lock.

public void
public void
public AutoLock.WithCondition
tryLock()

Overrides org.eclipse.jetty.util.thread.AutoLock.tryLock.

Tries to acquire the lock.

Inherited from org.eclipse.jetty.util.thread.AutoLock:
closeisHeldByCurrentThreadisLockednewCondition

Field Detail

_conditionback to summary
private final Condition _condition

Constructor Detail

WithConditionback to summary
public WithCondition()

Method Detail

awaitback to summary
public void await() throws InterruptedException
Exceptions
InterruptedException:
if the current thread is interrupted
See Also
Condition#await()
awaitback to summary
public boolean await(long time, TimeUnit unit) throws InterruptedException
Parameters
time:long

the time to wait

unit:TimeUnit

the time unit

Returns:boolean

false if the waiting time elapsed

Exceptions
InterruptedException:
if the current thread is interrupted
See Also
Condition#await(long, TimeUnit)
lockback to summary
public AutoLock.WithCondition lock()

Overrides org.eclipse.jetty.util.thread.AutoLock.lock.

Doc from org.eclipse.jetty.util.thread.AutoLock.lock.

Acquires the lock.

Returns:AutoLock.WithCondition

this AutoLock for unlocking

Annotations
@Override
signalback to summary
public void signal()
See Also
Condition#signal()
signalAllback to summary
public void signalAll()
See Also
Condition#signalAll()
tryLockback to summary
public AutoLock.WithCondition tryLock()

Overrides org.eclipse.jetty.util.thread.AutoLock.tryLock.

Doc from org.eclipse.jetty.util.thread.AutoLock.tryLock.

Tries to acquire the lock.

Whether the lock was acquired can be tested with isHeldByCurrentThread().

Typical usage of this method is in toString(), to avoid deadlocks when the implementation needs to lock to retrieve a consistent state to produce the string.

Returns:AutoLock.WithCondition

this AutoLock for unlocking

Annotations
@Override