Timer alternative to measure request rate on the server side
<p>I have client-server application in which i need to measure the rate of request arrival per second(Request rate). For this, i have a timer object that activates after every seconds, reads a synchronized counter and then sets it to zero. The counter increments on each request arrival.I used following code to detect request rate. There are so many other threads and timers in my application running.The problem is "due to the inaccuracy of timers i am not getting the perfect request rate". Is there any alternative of measuring request rate other than using timers.</p>

<pre><code>public class FrequencyDetector extends TimerTask {
RequestCounter requestCounter;
FrequencyHolder frequencyHolder;

    public FrequencyDetector(RequestCounter requestCounter,FrequencyHolder frequencyHolder){
    this.frequencyHolder=new FrequencyHolder();
    this.frequencyHolder=frequencyHolder;
    }

    @Override
    public void run() {
           int newFrequency=requestCounter.getCounter();
           frequencyHolder.setFrequency(newFrequency);
           requestCounter.setCounterToZero();
          //calls to other fuctions    
    }       

}
</code></pre>