I just thinking to build a cluster software in Linux in Java. I want to control the CPU load, for example, if CPU load is higher than a threshold, then I reduce execution thread sizes. I thought I could check CPU load once per second or a couple of seconds by a demon thread, how to implement it in Java? and How to implment in Java if I am going to check particular process is dead or not, and the port it opens is lost or not?
Share
There’s no way (AFAIK) to do this in pure Java. You could potentially write some native C to do this and then interface using JNA / JNI (which would be the most robust solution.)
Alternatively, a quick hacky easy approach (if you’re just using Linux) would be to use
Runtime.exec()to call one of these native approaches which you could then parse from within Java.In terms of checking whether a process is dead or not, you could use the above approach but with
ps.EDIT: This may be something that helps.