views:

79

answers:

2

Hi all,

How would I determine the current server load? Do I need to use JMX here to get the cpu time, or is there another way to determine that or something similar?

I basically want to have background jobs run only when the server is idle. I will use Quartz to fire the job every 30 minutes, check the server load then proceed if it is low or halt if it is busy.

Once I can determine how to measure the load (cpu time, memory usage), I can measure these at various points to determine how I want to configure the server.

Walter

A: 

I think you've answered your own question. If you want a pure Java solution, then the best that you can do is the information returned by the ThreadMXBean.

You can find out how many threads there are, how many processors the host machine has and how much time has been used by each thread, and calculate CPU load from that.

Dan Dyer
Thanks for your comment, I am using Quartz jobs so I will try low-priority threads to see how that works. I really don't need to know what the load is, I just want it to be the lowest priority on the list.
+1  A: 

Tricky to do in a portable way, it would likely depend considerably on your platform.

An alternative is to configure your Quartz jobs to run in low-priority threads. Quartz allows you to configure the thread factory, and if the server is busy, then the thread should be shuffled to the back of the pack until it can be run without getting in the way.

Also, if the load spikes in the middle of the job, then the VM will automatically throttle your batch job until the load drops again. It should be self-regulating, which you wouldn't get by manual introspection of the current load.

skaffman
Thanks, I will give this a shot. I don't really care about what the server load is, just that this gets the lowest priority and eventually will run.