I'm working with a RF reader device which has C# API.Based on its API, you'll need to manually invoke its read function to read/badge a card.
So my workaround is to use Timer to execute reading every 'n' seconds.
My problem is that Timer continuously executing, regardless of Thread.sleep() was invoke inside it's action.
Timer timer = new Timer(TimerCallback, null, 500, 1000); // From main() method
// The action that Timer executes
private void TimerCallback(Object o)
{
scan(); // Action for reading/badging card
scand.WaitOne(); // AutoResetEvent(true)
GC.Collect(); // Force garbage collection
}
Thread.sleep() invoke inside the scan().
In Java, I use synchronized() to wait the other thread to call invoke(). I've searched for the whole day and I can't see a workaround that will be equivalent to ScheduledExecutorService and synchronized().
I hope there is a workaround with this cause I need it as soon as possible.
Thanks!