Find out how much RAM is used by Thread
java, memory
Solution
The short answer is that all dynamicially allocated memory (heap) is shared by all threads unless you use Java's ThreadLocal class to declare variables that are local only to the thread.
In fact, the traditional Java memory model of shared data amongst threads (when not using ThreadLocal) is what makes threading so powerful for memory sharing across threads.
As sk4l mentioned there is a getThreadAllocatedBytes method of ThreadMXBean method if your JVM supports it, but keep in mind this is typically just an approximate value.
Lastly, most recent versions of the Oracle JDK and OpenJDK include jconsole and JDK 6u7 and later include VisualVM either of which you can use to attach to your process and see information about memory and threads.
Problem
I would like to know how to find out how much RAM is consumed by certain Threads. There are in my program about 15 classes, each is running in own Thread. So how can I discover how much RAM is used by Thread1, Thread2, ... Thread15? Is there any method for this? Thanks for replies!