Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


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 java.lang.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; coh 2010.08.13

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 increment()
          Increment the Long value of the ThreadLocalCounter for the current thread by one.
protected  java.lang.Long initialValue()
          Returns the current thread's initial value for this thread-local variable.

 

Methods inherited from class java.lang.ThreadLocal
get, remove, set

 

Constructor Detail

ThreadGate.ThreadLocalCounter

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

Method Detail

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()

initialValue

protected java.lang.Long initialValue()
Returns the current thread's initial value for this thread-local variable. This method will be invoked at most once per accessing thread for each thread-local, the first time the thread accesses the variable with the ThreadLocal.get() method. The initialValue method will not be invoked in a thread if the thread invokes the ThreadLocal.set(T) method prior to the get method.

This implementation simply returns null; if the programmer desires thread-local variables to be initialized to some value other than null, ThreadLocal must be subclassed, and this method overridden. Typically, an anonymous inner class will be used. Typical implementations of initialValue will invoke an appropriate constructor and return the newly constructed object.

Overrides:
initialValue in class java.lang.ThreadLocal
Returns:
the initial value for this thread-local

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.