I am using a variable time_of_last_call
as my origin of time; since nanoTime()
might give negative values, I can’t use 0 as my origin of time to initialize time_of_last_call
. If I initialize time_of_last_call
with Long.MIN_VALUE
I can have overflow issues. Any suggestions?
EDIT: I think I should just initialize it as:
long time_of_last_call = System.nanoTime()/1000000L;
//long time_of_last_call =Long.MIN_VALUE; //could have overflow issues
//long time_of_last_call =Long.MIN_VALUE/1000000; // could still have overflow issues?
//BEGIN OF CODE WITH A LOOP
// “time_of_last_call” may (or not) be updated:
if (some_condition)
time_of_last_call=System.nanoTime()/1000000L;
if ( ( System.nanoTime()/1000000L - time_of_last_call ) > 10 )
// do something
//END OF CODE WITH A LOOP