1

How can I get Windows cpu memory consumption of a particular Thread using java? I want to know only the memory usage not the cpu time.

  • There are hints, where You should google for: http://stackoverflow.com/questions/74674/how-to-do-i-check-cpu-and-memory-usage-in-java – icbytes Jun 06 '13 at 12:11
  • to simplify, the difference between threads and processes is that threads in a process share the same memory address space, so it can be said that the process's memory belongs to all the threads at the same time. – SirDarius Jun 06 '13 at 12:16
  • 3
    What is "cpu memory". That is two different concepts. If you want memory then remove the word CPU. – Gray Jun 06 '13 at 12:16

2 Answers2

1

How can I get Windows cpu memory consumption of a particular Thread using java? I want to know only the memory usage not the cpu time.

You can't. There is no way to tie heap-memory resources created in the JVM to the thread that created it since all threads share a common heap. There are stack memory allocated to each thread but I know of no way to determine how much stack space has been consumed by each thread.

A profiler is the best way for you to go but I don't think even they show you the owning thread. You may be able to infer this information from the object call stack however.

Gray
  • 115,027
  • 24
  • 293
  • 354
0

You want to do that in your code or with a tool ?

With a profiler like VisualVM, this is easy. But in Java, it is harder because the JVM treats the heap as shared not separated heaps for threads.

Baptiste Wicht
  • 7,472
  • 7
  • 45
  • 110