custom windows counter
I am writing a java applica开发者_如何学Ction which generate integer values at times. The java application is running on Windows machine. I don't know if this is possible but I was wondering if I can create a Windows counter "MyCounter" for these values so that I can track the "counter" in Windows Performances Monitor.
I don't think it's something that can be done in Java alone, but it could certainly be done using JNI. The JNI mechanism lets Java code interface with platform native code, so you'd create the counter in C++ (for example) and then invoke that C++ code from Java through JNI. JNA is a higher-lever layer on top of JNI which lets you do a lot of things on Windows without writing any native code yourself at all.
For Java applications it's standard to use JMX if you want to offer some monitoring for your application. Otherewise here is a tutorial for accessing windows performance counters from Java.
精彩评论