CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation

com.tangosol.util
Class ThreadGate.ThreadLocalCounter

java.lang.Object
  extended by java.lang.ThreadLocal
      extended by com.tangosol.util.ThreadGate.ThreadLocalCounter
Enclosing class:
ThreadGate

public static class ThreadGate.ThreadLocalCounter
extends ThreadLocal

Specialization of ThreadLocalObject that can be used for efficient thread local long counters.

This class associates a single Long value with the current thread. The Long value may be retrieved, set, removed, incremented, or decremented.

Author:
jh 2004.12.03

Constructor Summary
ThreadGate.ThreadLocalCounter()
          Create a new ThreadLocalCounter with an initial Long value of zero.
 
Method Summary
 long decrement()
          Decrement the Long value of the ThreadLocalCounter for the current thread by one.
 long getCount()
          Obtain the long value of the ThreadLocalCounter for the current thread.
 long increment()
          Increment the Long value of the ThreadLocalCounter for the current thread by one.
 void set(Object oValue)
          Set the Long value of the ThreadLocalCounter for the current thread.
 void setCount(long c)
          Set the long value of the ThreadLocalCounter for the current thread.
 
Methods inherited from class java.lang.ThreadLocal
get, initialValue, remove
 

Constructor Detail

ThreadGate.ThreadLocalCounter

public ThreadGate.ThreadLocalCounter()
Create a new ThreadLocalCounter with an initial Long value of zero.

Method Detail

getCount

public long getCount()
Obtain the long value of the ThreadLocalCounter for the current thread.

Returns:
the count for the current thread

setCount

public void setCount(long c)
Set the long value of the ThreadLocalCounter for the current thread.

Parameters:
c - the long counter value for the current thread
See Also:
getCount(), set(Object)

increment

public long increment()
Increment the Long value of the ThreadLocalCounter for the current thread by one. If the ThreadLocalCounter has been removed or its value is null, 1 is returned.

Returns:
the new Long value for the current thread or 1 if the ThreadLocalCounter has been removed or its value is null
See Also:
decrement()

decrement

public long decrement()
Decrement the Long value of the ThreadLocalCounter for the current thread by one. If the ThreadLocalCounter has been removed or its value is null, -1 is returned.

Returns:
the new Long value for the current thread or -1 if the ThreadLocalCounter has been removed or its value is null
See Also:
increment()

set

public void set(Object oValue)
Set the Long value of the ThreadLocalCounter for the current thread.

Overrides:
set in class ThreadLocal
Parameters:
oValue - the Long value for the current thread
Throws:
ClassCastException - if the supplied value is non-null and not an instance of Long

CoherenceTM v3.3
Copyright© 2000-2007 by Oracle Corporation