ehcache

net.sf.ehcache.concurrent
Class ConcurrencyUtil

java.lang.Object
  extended by net.sf.ehcache.concurrent.ConcurrencyUtil

public final class ConcurrencyUtil
extends Object

Various bits of black magic garnered from experts on the concurrency-interest@cs.oswego.edu mailing list.

Version:
$Id: ConcurrencyUtil.java 7837 2013-07-25 20:45:23Z cschanck $
Author:
Greg Luck

Method Summary
static int hash(Object object)
          Returns a hash code for non-null Object x.
static int selectLock(Object key, int numberOfLocks)
          Selects a lock for a key.
static void shutdownAndWaitForTermination(ExecutorService pool, int waitSeconds)
          Properly shutdown and await pool termination for an arbitrary amount of time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hash

public static int hash(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(Object key,
                             int numberOfLocks)
                      throws CacheException
Selects 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(ExecutorService pool,
                                                 int waitSeconds)
                                          throws TimeoutException
Properly shutdown and await pool termination for an arbitrary amount of time.

Parameters:
pool - Pool to shutdown
waitSeconds - Seconds to wait before throwing exception
Throws:
TimeoutException - Thrown if the pool does not shutdown in the specified time

ehcache

Copyright 2001-2014, Terracotta, Inc.