0

I created a program in java and I want to know its CPU usage when it is being run. Is there any function? Can you help me please?

Thank you in advance!

1

4 Answers 4

2

Use the tools in your operating system, say: in Windows you can see this information in the task manager, or in Linux use the top command.

Sign up to request clarification or add additional context in comments.

2 Comments

I think he wants to do it programatically.
@JBentley that's possible, yes. I'm just providing a simpler alternative, it might be enough to meet the OP's needs.
0

I would suggest running jconsole, it will give you these statistics for all currently running Java applications. It can be found in the bin directory of your Java installation.

Comments

0

This might be useful. The link will take you to an older post with a similar problem.

7 Comments

This should be a comment, not an answer
Sorry... what's the difference? I'm relatively new to SO
An answer contains a solution to the problem. Anything else should be a comment.
Providing a link is not really an answer, it should be posted as a comment in the question. Now if you add some additional information, an explanation, or some code, then that should be posted as an answer. As it is, this answer is risking getting downvoted (not by me, but who knows if someone else decides to do it?)
Until he hits 50 reputation, he cannot just leave comments.
|
0

Use the tool that comes with the java SDK called VisualVM. It can show you much much more than just CPU usage, in real time.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.