I verified that system.currentTimeMillis returns walltime instead of
monotonic time so it cannot be used to calculate timeouts. 
The problem here concerns every situation where walltime has shifted somehow
and adjusted back, for example when system clock is somehow drifted enough
and NTP is used to adjust the clock. 
I did a short test program:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.Console;
import java.io.IOException;
import java.lang.*;

public class JavaTimeTest
{
    public static void main(String[] args)
    {
        DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");

        long currentTimeBefore = System.currentTimeMillis();
        System.out.println("Current time is now: " + currentTimeBefore +
"ms");
        System.out.println("As DateTime it is: " +
dateFormat.format(currentTimeBefore));

        System.out.println("Change time and press enter to continue...");
        try 
        {
            System.in.read();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }

        long currentTimeAfter = System.currentTimeMillis();
        System.out.println("Current time is now: " + currentTimeAfter +
"ms");
        System.out.println("As DateTime it is: " +
dateFormat.format(currentTimeAfter));

        long timeDiff = currentTimeAfter - currentTimeBefore;
        System.out.println("Difference is: " + timeDiff + "ms");
    }
}

.. and the printout looks like this when I manually change system time a day
forward:

Current time is now: 1542964907800ms
As DateTime it is: 23.11.2018 11:21:47
Change time and press enter to continue...

(...at this point I changed system time manually...)

Current time is now: 1543051313048ms
As DateTime it is: 24.11.2018 11:21:53
Difference is: 86405248ms

I hope this clarifies the problem.

-- 
Sami




--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to