Thursday, June 29, 2023

Double Timeout

 This article was posted on JRoller on October 9, 2013

The other day, I needed to check if a configuration parameter giving a timeout in number of seconds was really used by our communication layer. I came to the point in the code where we are sending a request and giving the timeout parameter to the lower layer method (a standard market product). The thing that caught my attention was that the method timeout parameter was of type double.

So I decided to decompile the code just to check why on earth they decided upon a double. This led me to the following conversion method (this is decompiled code, so the constants are already inlined):

static final long toMillis(double d)
{
    if(d == 0.0D)
        return 0L;
        
    double d1 = (d + 0.00050000000000000001D) * 1000D;

    if(d1 >= 9.2233720368547758E+018D)
        return 9223372036854775807L;

    return (long)d1;
}

So yes, it is converted to a long in some strange way. Maybe they want to cope with milliseconds or even nanoseconds in a future version?

No comments:

Post a Comment