It looks like you might want to take a βlistenerβ approach. Allow your cruncher number to register listeners, then every 100-200 cycles (customizable) (or in some conditions changes), notify listeners of an update that they should be aware of.
The listener may be another class that has a wait () thread, and when it receives a notification, it simply updates its internal variable and then notifies the waiting thread. Then, the quick loop class has a quick way to update the external value and does not worry about accessing the fast-changing internal state.
In another thread, wait () s can also be wait () in a timer thread that is set to 10-20HZ (configurable) to wait on the timer until it waits () the next time it updates from your synchronized class.
source share