Efficient way of getting thread CPU time using JMX

后端 未结 5 1005
后悔当初
后悔当初 2020-12-31 22:19

I\'m currently getting the total thread CPU time using JMX in the following manner:

private long calculateTotalThreadCpuTime(ThreadMXBean thread) {

    long         


        
5条回答
  •  感情败类
    2020-12-31 22:55

    The cause of the poor performance is that each call of thread.getThreadCpuTime() will (in your case of a remote proxy) most probably result in an RMI/Remote JMX call which of course is expensive, especially when the message is actually sent via TCP (and maybe even outside localhost). (see JMX 1.4 spec, chapter 7.3)

    Although JMX defines multiple attribute retrieval at once this will not help you out here because thread.getThreadCpuTime(long) is not an JMX attribute but a remote method invocation (and additionally, the ThreadInfo object on which the methods is invoked differs by each call)

    Unfortunately, the JMX 1.4 spec does not define something like "invoke multiple methods of multiple objects and return their return values at all". So beside concurrent invocation (which will save time but will not reduce the effort) of these calls I am not aware of any (compatible) optimizations here.

提交回复
热议问题