JDK-6326629 : (thread spec) Modernize ThreadLocal code example
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2005-09-21
  • Updated: 2010-04-02
  • Resolved: 2005-09-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
Description
The code example "SerialNum" in the class comment for ThreadLocal
can be better written using modern Java idioms:

class SerialNum {
    private static ThreadLocal<Integer> serialNum
	= new ThreadLocal<Integer>()
    {
	// The next serial number to be assigned
	private int nextSerialNum = 0;

	protected synchronized Integer initialValue() {
            return nextSerialNum++;
        }
    };

    public static int get() {
        return serialNum.get();
    }
}