Package com.oracle.coherence.common.base
Class Blocking
java.lang.Object
com.oracle.coherence.common.base.Blocking
Blocking provides a set of helper methods related to blocking a thread.
- Author:
- mf 2015.02.24
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.static void
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.static void
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.static void
connect
(Socket socket, SocketAddress addr) Connect a socket while still respecting the calling thread'stimeout
.static void
connect
(Socket socket, SocketAddress addr, int cMillis) Connect a socket within a given timeout while still respecting the calling thread'stimeout
.static boolean
Return true if the thread is interrupted ortimed out
.static void
lockInterruptibly
(Lock lock) Acquire a lock while still respecting the calling thread'stimeout
.static void
Invoke LockSupport.park() while still respecting the calling thread'stimeout
.static void
Invoke LockSupport.parkNanos() while still respecting the calling thread'stimeout
.static int
Wait on the Selector while still respecting the calling thread'stimeout
.static int
Wait on the Selector while still respecting the calling thread'stimeout
.static void
sleep
(long cMillis) Invoke Thread.sleep() while still respecting the calling thread'stimeout
.static void
sleep
(long cMillis, int cNanos) Invoke Thread.sleep() while still respecting the calling thread'stimeout
.static boolean
Attempt to acquire a lock while still respecting the calling thread'stimeout
.static void
Wait on the the specified monitor while still respecting the calling thread'stimeout
.static void
Wait on the specified monitor while still respecting the calling thread'stimeout
.static void
Wait on the specified monitor while still respecting the calling thread'stimeout
.
-
Constructor Details
-
Blocking
public Blocking()
-
-
Method Details
-
interrupted
public static boolean interrupted()Return true if the thread is interrupted ortimed out
. Note as with Thread.interrupted this will clear the interrupted flag if it is set, it will not however clear the timeout.- Returns:
- true if the thread is interrupted or
timed out
-
wait
Wait on the the specified monitor while still respecting the calling thread'stimeout
.- Parameters:
oMonitor
- the monitor to wait on- Throws:
InterruptedException
- if the thread is interrupted
-
wait
Wait on the specified monitor while still respecting the calling thread'stimeout
.- Parameters:
oMonitor
- the monitor to wait oncMillis
- the maximum number of milliseconds to wait- Throws:
InterruptedException
- if the thread is interrupted
-
wait
Wait on the specified monitor while still respecting the calling thread'stimeout
.- Parameters:
oMonitor
- the monitor to wait oncMillis
- the maximum number of milliseconds to waitcNanos
- the additional number of nanoseconds to wait- Throws:
InterruptedException
- if the thread is interrupted
-
sleep
Invoke Thread.sleep() while still respecting the calling thread'stimeout
.- Parameters:
cMillis
- the maximum number of milliseconds to sleep- Throws:
InterruptedException
- if the thread is interrupted
-
sleep
Invoke Thread.sleep() while still respecting the calling thread'stimeout
.- Parameters:
cMillis
- the maximum number of milliseconds to sleepcNanos
- the additional number of nanoseconds to sleep- Throws:
InterruptedException
- if the thread is interrupted
-
park
Invoke LockSupport.park() while still respecting the calling thread'stimeout
.- Parameters:
oBlocker
- the blocker
-
parkNanos
Invoke LockSupport.parkNanos() while still respecting the calling thread'stimeout
.- Parameters:
oBlocker
- the blockercNanos
- the maximum number of nanoseconds to park for
-
lockInterruptibly
Acquire a lock while still respecting the calling thread'stimeout
.- Parameters:
lock
- the lock to acquire- Throws:
InterruptedException
- if the thread is interrupted
-
tryLock
Attempt to acquire a lock while still respecting the calling thread'stimeout
.- Parameters:
lock
- the lock to acquiretime
- the maximum amount of time to try forunit
- the unit which time represents- Returns:
- true iff the lock was acquired
- Throws:
InterruptedException
- if the thread is interrupted
-
await
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.- Parameters:
cond
- the condition to wait on- Throws:
InterruptedException
- if the thread is interrupted
-
await
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.- Parameters:
cond
- the condition to wait oncNanos
- the maximum amount of time to wait- Throws:
InterruptedException
- if the thread is interrupted
-
await
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.- Parameters:
cond
- the condition to wait ontime
- the maximum amount of time to waitunit
- the unit which time represents- Throws:
InterruptedException
- if the thread is interrupted
-
select
Wait on the Selector while still respecting the calling thread'stimeout
. If the thread performing the select is interrupted, this method will return immediately and that thread's interrupted status will be set.- Parameters:
selector
- the selector to wait on- Returns:
- the number of keys, possibly zero, whose ready-operation sets were updated
- Throws:
IOException
- if an I/O error occurs
-
select
Wait on the Selector while still respecting the calling thread'stimeout
. If the thread performing the select is interrupted, this method will return immediately and that thread's interrupted status will be set.- Parameters:
selector
- the selector to wait oncMillis
- the maximum amount of time to wait- Returns:
- the number of keys, possibly zero, whose ready-operation sets were updated
- Throws:
IOException
- if an I/O error occurs
-
connect
Connect a socket while still respecting the calling thread'stimeout
.- Parameters:
socket
- the socket to connectaddr
- the address to connect to- Throws:
IOException
- in an IO error occurs
-
connect
Connect a socket within a given timeout while still respecting the calling thread'stimeout
.- Parameters:
socket
- the socket to connectaddr
- the address to connect tocMillis
- the caller specified connect timeout- Throws:
IOException
- in an IO error occurs
-