Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out how much RAM is used by Thread

Tags:

java

memory

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!

like image 869
PerwinCZ Avatar asked Jul 13 '13 14:07

PerwinCZ


People also ask

How do I know how much RAM is being used?

Click the Memory tab. It's on the top-left side of the "Task Manager" window. You'll be able to view how much of your computer's RAM is being used in graph format near the top of the page, or by looking at the number beneath the "In use (Compressed)" heading. Double-click the "My PC" icon.

How do I Check my RAM usage on a Mac?

Check your total RAM consumption 1 To see how much RAM is currently being consumed, in the MacOS menu bar click on Go ... 2 And then select Utilities. Double-click on Activity Monitor. 3 Click on the Memory tab. This is where you see all running processes and (near the lower part) how much memory is being... More ...

How to check installed RAM memory in Windows 10?

To check the installed RAM memory, I suggest you to follow the steps: Click on Start. Right click on Computer and select Properties. In System Properties window, under section System, see Installed Memory (RAM) to know the memory installed on your computer.

How much RAM do I have in Windows 7?

On Windows 10, click on Memory to look at your current RAM usage. Windows 7 users see their memory under Total. (In the Windows 10 screenshot above, we’re using 8.6, or 54%, of the total 16 GB of available RAM. In the Windows 7 screenshot below, we have 1,000 MB, or 1 GB, of total RAM.)


1 Answers

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.

like image 123
linguanerd Avatar answered Oct 05 '22 23:10

linguanerd