I'm testing something and I want print out execution time with this code:
private Runnable runnerLog = new Runnable() {
@Override
public void run() {
String timeStamp = new SimpleDateFormat("HH:mm:ss yyyy-dd-MM").format(Calendar.getInstance().getTime());
System.out.println("Current time: " + timeStamp);
mHandlerLogger.postDelayed(runnerLog, mInterval);
}};
The result should be like:
13:45:10 13:45:12 13:45:14 13:45:16 and so on...
but i noticed that sometimes is not difference 2 seconds, but three:
13:45:10 13:45:12 13:45:15 13:45:17 13:45:19 13:45:21 13:45:24
What is the reason for this situation? Is there better solution for executing something each X seconds?