Top Description Fields Constructors Methods
net.sf.ehcache.concurrent

public final Class ConcurrencyUtil

extends Object
Class Inheritance
Imports
net.sf.ehcache.CacheException, java.util.concurrent.ExecutorService, .TimeUnit, .TimeoutException

Various bits of black magic garnered from experts on the [email protected] mailing list.
Author
Greg Luck
Version
$Id: ConcurrencyUtil.java 10789 2018-04-26 02:08:13Z adahanne $

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final int
private static final int

Constructor Summary

AccessConstructor and Description
private
ConcurrencyUtil()

Utility class therefore precent construction

Method Summary

Modifier and TypeMethod and Description
public static int

Returns:

the hash code
hash
(Object
the object serving as a key
object
)

Returns a hash code for non-null Object x.

public static int

Returns:

the selected lock index
selectLock
(final Object key, int numberOfLocks)

Selects a lock for a key.

public static void
shutdownAndWaitForTermination(ExecutorService
Pool to shutdown
pool
,
int
Seconds to wait before throwing exception
waitSeconds
)

Properly shutdown and await pool termination for an arbitrary amount of time.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DOUG_LEA_BLACK_MAGIC_OPERAND_1back to summary
private static final int DOUG_LEA_BLACK_MAGIC_OPERAND_1
DOUG_LEA_BLACK_MAGIC_OPERAND_2back to summary
private static final int DOUG_LEA_BLACK_MAGIC_OPERAND_2
DOUG_LEA_BLACK_MAGIC_OPERAND_3back to summary
private static final int DOUG_LEA_BLACK_MAGIC_OPERAND_3
DOUG_LEA_BLACK_MAGIC_OPERAND_4back to summary
private static final int DOUG_LEA_BLACK_MAGIC_OPERAND_4

Constructor Detail

ConcurrencyUtilback to summary
private ConcurrencyUtil()

Utility class therefore precent construction

Method Detail

hashback to summary
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:Object

the object serving as a key

Returns:int

the hash code

selectLockback to summary
public static int selectLock(final Object key, int numberOfLocks) throws CacheException

Selects a lock for a key. The same lock is always used for a given key.

Returns:int

the selected lock index

shutdownAndWaitForTerminationback to summary
public static void shutdownAndWaitForTermination(ExecutorService pool, int waitSeconds) throws TimeoutException

Properly shutdown and await pool termination for an arbitrary amount of time.

Parameters
pool:ExecutorService

Pool to shutdown

waitSeconds:int

Seconds to wait before throwing exception

Exceptions
TimeoutException:
Thrown if the pool does not shutdown in the specified time