Re: sampling rate problem
"wanwan" <ericwan78@yahoo.com> wrote in message
news:1163191311.122185.46730@m7g2000cwm.googlegroups.com...
First, this is a threading nightmare.
You need to syncronize so that your reading of mousepos_x and
mousepos_y is atomic. Also, there is no guaranty that your other
thread's data will be accessible to this thread unless you syncronize.
I don't need the mouse positions to be precise to the pixel. I wrote
this class strictly for the purpose of data collection. Data analysis
is not done in real time.
It would ALSO probably be better for you to use the Timer class,
instead of busy-waiting.
Since I made the mouse sampling class a thread, it is doing something
independent of the rest of the software (I am writing a GUI). So I
thought it'd be same idea as Timer class
The other suggestion I have for you is to instead use temporal event
based updates (calculating the change in time from the last position),
rather than polling every n milliseconds.
What is a temporal event? It sounds like interrupt vs polling in asm.
But what in Java can achieve the interrupt effect?
The real question I have for you is, why do you want to sample mouse
movement at all? Is it for some sort of macro? Just an excercise?
Something else that could be done using standard libraries instead of
writing your own sampling method?
It is a software used for engineering research purposes
Well, hope the suggestions help, good luck finding the right way.
Thanks
Since it is unlikely that you will ever get exact timing from sleep or timer
facilities in Java (they make disclaimers about precision and accuracy), it
is better to turn the problem on its head. You get mouse move events from
the system. Check the system time when you get the event, and calculate the
time between events.
I had a similar problem getting accurate timer delays while measuring wind
speed in a weather application that I wrote. I finally realized that I could
use the timer to provide reasonably periodic wake-up events, but I needed to
determine the actual interval since the last event and calculate the wind
velocity using the measured time interval. This works even when huge delays
due to other applications bogging down the system (which can cause delays of
several seconds in some cases). I wrote an article about it - want to read
it? Here it goes: http://mysite.verizon.net/Karl_Uppiano/winddata.html