Skip to content

ThreadLocal and Java class structure

May 11, 2010

Question 1: How can a static thread local have reference to a variable instance level information?

Firstly Threads share process resources. Thread can have their local data on stack.

Quote wiki : Stack
Each thread has a reserved region of memory referred to as its stack. When a function executes, it may add some of its state data to the top of the stack; when the function exits it is responsible for removing that data from the stack. At a minimum, a thread’s stack is used to store the location of function calls and return. LIFO stack allocation is very simple and typically faster than heap. Negative point is thread’s stack size can be as small as a few dozen kilobytes.

So, in java ThreadLocal class uses map internally to store information and it gets the reference of the current thread and the information to put inside it using the ThreadLocalMap class. If you create a static ThreadLocal object reference it does not impact the way the usage is done – since its specific to the executing thread.

Question 2: What is the structure of java class.

My Very Cute Animal Turns Savage In Full Moon Areas.
Magic Number: 0xCAFEBABE
Version of Class File Format: the minor and major versions of the class file
Constant Pool: Pool of constants for the class
Access Flags: for example whether the class is abstract, static, etc
This Class: The name of the current class
Super Class: The name of the super class
Interfaces: Any interfaces in the class
Fields: Any fields in the class
Methods: Any methods in the class
Attributes: Any attributes of the class (for example the name of the sourcefile, etc)

Wiki Link:

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: