net.sf.ehcache.constructs.concurrent

Class 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 124 2006-06-11 13:44:17Z gregluck $

Author: Greg Luck

Method Summary
static inthash(Object object)
Returns a hash code for non-null Object x.
static intselectLock(Object key, int numberOfLocks)
Selects a lock for a key.

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)
Selects a lock for a key. The same lock is always used for a given key.

Parameters: key

Returns: the selected lock index