Package net.sf.ehcache.concurrent
Class ConcurrencyUtil
- java.lang.Object
-
- net.sf.ehcache.concurrent.ConcurrencyUtil
-
public final class ConcurrencyUtil extends java.lang.ObjectVarious bits of black magic garnered from experts on the concurrency-interest@cs.oswego.edu mailing list.- Version:
- $Id$
- Author:
- Greg Luck
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static inthash(java.lang.Object object)Returns a hash code for non-null Object x.static intselectLock(java.lang.Object key, int numberOfLocks)Selects a lock for a key.static voidshutdownAndWaitForTermination(java.util.concurrent.ExecutorService pool, int waitSeconds)Properly shutdown and await pool termination for an arbitrary amount of time.
-
-
-
Method Detail
-
hash
public static int hash(java.lang.Object object)
Returns a hash code for non-null Object x.This function ensures that hashCodes that differ only by constant multiples at each bit position have a bounded number of collisions. (Doug Lea)
- Parameters:
object- the object serving as a key- Returns:
- the hash code
-
selectLock
public static int selectLock(java.lang.Object key, int numberOfLocks) throws CacheExceptionSelects a lock for a key. The same lock is always used for a given key.- Parameters:
key-- Returns:
- the selected lock index
- Throws:
CacheException
-
shutdownAndWaitForTermination
public static void shutdownAndWaitForTermination(java.util.concurrent.ExecutorService pool, int waitSeconds) throws java.util.concurrent.TimeoutExceptionProperly shutdown and await pool termination for an arbitrary amount of time.- Parameters:
pool- Pool to shutdownwaitSeconds- Seconds to wait before throwing exception- Throws:
java.util.concurrent.TimeoutException- Thrown if the pool does not shutdown in the specified time
-
-