Package com.oracle.coherence.common.base
Class Blocking
- java.lang.Object
-
- com.oracle.coherence.common.base.Blocking
-
public class Blocking extends Object
Blocking provides a set of helper methods related to blocking a thread.- Author:
- mf 2015.02.24
-
-
Constructor Summary
Constructors Constructor Description Blocking()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
await(Condition cond)
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.static void
await(Condition cond, long cNanos)
Await for the Condition to be signaled while still respecting the calling thread'stimeout
.static void
await(Condition cond, long time, TimeUnit unit)
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
interrupted()
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
park(Object oBlocker)
Invoke LockSupport.park() while still respecting the calling thread'stimeout
.static void
parkNanos(Object oBlocker, long cNanos)
Invoke LockSupport.parkNanos() while still respecting the calling thread'stimeout
.static int
select(Selector selector)
Wait on the Selector while still respecting the calling thread'stimeout
.static int
select(Selector selector, long cMillis)
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
tryLock(Lock lock, long time, TimeUnit unit)
Attempt to acquire a lock while still respecting the calling thread'stimeout
.static void
wait(Object oMonitor)
Wait on the the specified monitor while still respecting the calling thread'stimeout
.static void
wait(Object oMonitor, long cMillis)
Wait on the specified monitor while still respecting the calling thread'stimeout
.static void
wait(Object oMonitor, long cMillis, int cNanos)
Wait on the specified monitor while still respecting the calling thread'stimeout
.
-
-
-
Method Detail
-
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
public static void wait(Object oMonitor) throws InterruptedException
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
public static void wait(Object oMonitor, long cMillis) throws InterruptedException
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
public static void wait(Object oMonitor, long cMillis, int cNanos) throws InterruptedException
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
public static void sleep(long cMillis) throws InterruptedException
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
public static void sleep(long cMillis, int cNanos) throws InterruptedException
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
public static void park(Object oBlocker)
Invoke LockSupport.park() while still respecting the calling thread'stimeout
.- Parameters:
oBlocker
- the blocker
-
parkNanos
public static void parkNanos(Object oBlocker, long cNanos)
Invoke LockSupport.parkNanos() while still respecting the calling thread'stimeout
.- Parameters:
oBlocker
- the blockercNanos
- the maximum number of nanoseconds to park for
-
lockInterruptibly
public static void lockInterruptibly(Lock lock) throws InterruptedException
Acquire a lock while still respecting the calling thread'stimeout
.- Parameters:
lock
- the lock to acquire- Throws:
InterruptedException
- if the thread is interrupted
-
tryLock
public static boolean tryLock(Lock lock, long time, TimeUnit unit) throws InterruptedException
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
public static void await(Condition cond) throws InterruptedException
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
public static void await(Condition cond, long cNanos) throws InterruptedException
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
public static void await(Condition cond, long time, TimeUnit unit) throws InterruptedException
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
public static int select(Selector selector) throws IOException
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
public static int select(Selector selector, long cMillis) throws IOException
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
public static void connect(Socket socket, SocketAddress addr) throws IOException
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
public static void connect(Socket socket, SocketAddress addr, int cMillis) throws IOException
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
-
-