Top Description Fields Constructors Methods
org.wildfly.common.lock

public Class SpinLock

extends Object
implements ExtendedLock
Class Inheritance
All Implemented Interfaces
org.wildfly.common.lock.ExtendedLock, java.util.concurrent.locks.Lock
Static Imports
org.wildfly.common.lock.JDKSpecific.unsafe

A spin lock. Such locks are designed to only be held for a very short time - for example, long enough to compare and swap two fields. The lock may degrade to yielding the thread after a certain number of spins if it is held for too long.

Spin locks do not support conditions, and they do not support timed waiting. Normally only the uninterruptible lock, tryLock, and unlock methods should be used to control the lock.

Field Summary

Modifier and TypeField and Description
private static final int
private int
private volatile Thread
private static final long
private final int

Constructor Summary

AccessConstructor and Description
public
SpinLock()

Construct a new instance.

public
SpinLock(final int
the spin limit to use for this instance
spinLimit
)

Construct a new instance with the given spin limit.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true; the lock is fair
isFair
()

Implements org.wildfly.common.lock.ExtendedLock.isFair.

Determine if this lock is fair.
public boolean

Returns:

true if the lock is held by the calling thread, false otherwise
isHeldByCurrentThread
()

Implements org.wildfly.common.lock.ExtendedLock.isHeldByCurrentThread.

Determine if this spin lock is held by the calling thread.
public boolean

Returns:

true if the lock is held by any thread, false otherwise
isLocked
()

Implements org.wildfly.common.lock.ExtendedLock.isLocked.

Determine if this spin lock is held.
public void
lock()

Implements java.util.concurrent.locks.Lock.lock.

Acquire the lock by spinning until it is held.
public void
lockInterruptibly()

Implements java.util.concurrent.locks.Lock.lockInterruptibly.

Acquire the lock by spinning until it is held or the thread is interrupted.
public Condition

Returns:

nothing
newCondition
()

Implements java.util.concurrent.locks.Lock.newCondition.

Unsupported.
public boolean

Returns:

true if the lock was acquired, false otherwise
tryLock
()

Implements java.util.concurrent.locks.Lock.tryLock.

Try to acquire the lock, returning immediately whether or not the lock was acquired.
public boolean

Returns:

nothing
tryLock
(final long
ignored
time
,
final TimeUnit
ignored
unit
)

Implements java.util.concurrent.locks.Lock.tryLock.

Unsupported.
public void
unlock()

Implements java.util.concurrent.locks.Lock.unlock.

Release the lock.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

defaultSpinLimitback to summary
private static final int defaultSpinLimit
levelback to summary
private int level
ownerback to summary
private volatile Thread owner
Annotations
@SuppressWarnings:unused
ownerOffsetback to summary
private static final long ownerOffset
spinLimitback to summary
private final int spinLimit

Constructor Detail

SpinLockback to summary
public SpinLock()

Construct a new instance.

SpinLockback to summary
public SpinLock(final int spinLimit)

Construct a new instance with the given spin limit.

Parameters
spinLimit:int

the spin limit to use for this instance

Method Detail

isFairback to summary
public boolean isFair()

Implements org.wildfly.common.lock.ExtendedLock.isFair.

Determine if this lock is fair.

Returns:boolean

true; the lock is fair

isHeldByCurrentThreadback to summary
public boolean isHeldByCurrentThread()

Implements org.wildfly.common.lock.ExtendedLock.isHeldByCurrentThread.

Determine if this spin lock is held by the calling thread. Useful for assertions.

Returns:boolean

true if the lock is held by the calling thread, false otherwise

isLockedback to summary
public boolean isLocked()

Implements org.wildfly.common.lock.ExtendedLock.isLocked.

Determine if this spin lock is held. Useful for assertions.

Returns:boolean

true if the lock is held by any thread, false otherwise

lockback to summary
public void lock()

Implements java.util.concurrent.locks.Lock.lock.

Acquire the lock by spinning until it is held.

lockInterruptiblyback to summary
public void lockInterruptibly() throws InterruptedException

Implements java.util.concurrent.locks.Lock.lockInterruptibly.

Acquire the lock by spinning until it is held or the thread is interrupted.

Exceptions
InterruptedException:
if the thread is interrupted before the lock can be acquired
newConditionback to summary
public Condition newCondition() throws UnsupportedOperationException

Implements java.util.concurrent.locks.Lock.newCondition.

Unsupported.

Returns:Condition

nothing

Exceptions
UnsupportedOperationException:
always
tryLockback to summary
public boolean tryLock()

Implements java.util.concurrent.locks.Lock.tryLock.

Try to acquire the lock, returning immediately whether or not the lock was acquired.

Returns:boolean

true if the lock was acquired, false otherwise

tryLockback to summary
public boolean tryLock(final long time, final TimeUnit unit) throws UnsupportedOperationException

Implements java.util.concurrent.locks.Lock.tryLock.

Unsupported.

Parameters
time:long

ignored

unit:TimeUnit

ignored

Returns:boolean

nothing

Exceptions
UnsupportedOperationException:
always
unlockback to summary
public void unlock()

Implements java.util.concurrent.locks.Lock.unlock.

Release the lock.

Exceptions
IllegalMonitorStateException:
if the lock is not held by the current thread