[concurrency-interest] deadline and long overflow

Doug Lea dl at cs.oswego.edu
Wed Apr 20 08:52:03 EDT 2016


On 04/20/2016 06:32 AM, Alex Otenko wrote:
> Wouldn’t that be a deadline of 500-odd years?

Overflow issues can occur in half that time though (around 292 years).

>
> Technically, overflow is a possibility. Practically - very unlikely.
>

Right. There is a disclaimer about this in System.nanotime:
http://docs.oracle.com/javase/8/docs/api/java/lang/System.html#nanoTime--

This could be repeated in every timing-related method, but isn't.

-Doug

> Alex
>
>> On 20 Apr 2016, at 11:05, Peter Veentjer <alarmnummer at gmail.com
>> <mailto:alarmnummer at gmail.com>> wrote:
>>
>> I have a question regarding dealing with deadlines and long overflow.
>>
>> For example the following from the SynchronousQueue:
>>
>> final long deadline = timed ? System.nanoTime() + nanos :0L;
>> What would happen if someone calls queue.offer(item, Long.MAX_VALUE, NANOS)
>> then deadline overflows and becomes negative. I see the same approach in other
>> parts e.g.
>>
>> this.deadline = timed ? System.nanoTime() + nanos :0L;
>> from the Phaser. Personally I like the simplicity; but my concern is regarding
>> validity.
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest at cs.oswego.edu <mailto:Concurrency-interest at cs.oswego.edu>
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>





More information about the Concurrency-interest mailing list