Re: Durations in existing JDK APIs

2018-06-16 Thread Stephen Colebourne
Without commenting on the proposed implementation below, Future seems like a good place to start. I suspect that ExecutorService and ScheduledExecutorService would also be good targets to enhance. Stephen On Fri, 15 Jun 2018, 18:43 Martin Buchholz, wrote: > > > On Wed, May 30, 2018 at 11:32 AM,

Re: Durations in existing JDK APIs

2018-06-15 Thread Martin Buchholz
On Wed, May 30, 2018 at 11:32 AM, Doug Lea wrote: > > The original rationale for designing j.u.c.TimeUnit using the Flyweight > pattern was to to reduce allocation and GC-related overhead and timing > jitter for methods that otherwise may operate on the order of > nanoseconds. But there are many

Re: Durations in existing JDK APIs

2018-06-11 Thread Stephen Colebourne
Finally got to check the logic in convert(Duration), and it looks fine to me. All three look good thanks Stephen (not an OpenJDK reviewer). On 6 June 2018 at 18:03, Martin Buchholz wrote: > OK, here is a RFR for low-hanging changes (some of these changes have > already been reviewed by some of

Re: Durations in existing JDK APIs

2018-06-06 Thread Roger Riggs
Hi Martin, All three look fine to me.  +3 Roger On 6/6/18 1:03 PM, Martin Buchholz wrote: OK, here is a RFR for low-hanging changes (some of these changes have already been reviewed by some of you): 8204375: Add TimeUnit#convert(Duration)

Re: Durations in existing JDK APIs

2018-06-06 Thread Martin Buchholz
OK, here is a RFR for low-hanging changes (some of these changes have already been reviewed by some of you): 8204375: Add TimeUnit#convert(Duration) http://cr.openjdk.java.net/~martin/webrevs/jdk/jsr166-integration/convertDuration/index.html https://bugs.openjdk.java.net/browse/JDK-8204375

Re: Durations in existing JDK APIs

2018-06-05 Thread Martin Buchholz
JDK-8204375: Add TimeUnit#convert(Duration)

Re: Durations in existing JDK APIs

2018-06-04 Thread Martin Buchholz
Looks like if you switch representation for negative Duration, much of the hair goes away. This version also optimizes for NANOSECONDS, which is very likely to be the target in practice: public long convert(Duration duration) { long secs = duration.getSeconds(); int nano =

Re: Durations in existing JDK APIs

2018-06-04 Thread Martin Buchholz
TimeUnit#toDuration is gone. Here's a non-strawman attempt at TimeUnit#convert(Duration). I was astonished how hard it was to get this really correct instead of merely mostly correct. For negative numbers, the long/int representation of Duration is sort-of a "floored" division instead of java's

Re: [concurrency-interest] Durations in existing JDK APIs

2018-06-01 Thread Gregg Wonderly
I am not sure I understand this implementation, but isn’t >long s = convert(duration.getSeconds(), SECONDS); needing to actually be >long s = convert(duration.getSeconds(), NANOSECONDS); so that s+n is in a common unit of measure? Gregg > On May 30, 2018, at 7:19 PM, Martin

Re: Durations in existing JDK APIs

2018-05-31 Thread Stephen Colebourne
I'm not convinced TimeUnit::toDuration(long amount) has enough value. We don't have a similar method on ChronoUnit Duration.of(amount, timeUnit.toChronoUnit()) seems sufficient. Maybe document this in the convert(Duration) method? Stephen On 31 May 2018 at 01:19, Martin Buchholz wrote: >

Re: Durations in existing JDK APIs

2018-05-31 Thread Martin Buchholz
In j.u.concurrent the APIs bottom out in something that just takes a long nanos, like LockSupport.parkNanos, so there's no advantage to converting to TimeUnit-based durations greater than 292 years. And returning multiple values in Java remains clumsy. On Wed, May 30, 2018 at 11:06 PM, Peter

Re: Durations in existing JDK APIs

2018-05-31 Thread Peter Levart
Just thinking loud... On 05/30/18 19:36, Martin Buchholz wrote: Obvious progress would seem to be more conversion methods. Conversion code tends to be annoying/errorprone because of having to deal with overflow. Stephen/Doug: is there any reason we didn't add conversions between Duration and

Re: [concurrency-interest] Durations in existing JDK APIs

2018-05-30 Thread Martin Buchholz
On Wed, May 30, 2018 at 7:43 PM, Gregg Wonderly wrote: > I am not sure I understand this implementation, but isn’t > > >long s = convert(duration.getSeconds(), SECONDS); > > needing to actually be > > >long s = convert(duration.getSeconds(), NANOSECONDS); > > so that s+n is in a

Re: Durations in existing JDK APIs

2018-05-30 Thread Martin Buchholz
v.0.2 has both conversion methods in TimeUnit. The unexpected weirdness is that convert(Duration) saturates while toDuration throws ArithmeticException, but both seem author-culture-consistent. Perhaps TimeUnit#toDuration doesn't provide enough value in view of the existing Duration.of and

Re: Durations in existing JDK APIs

2018-05-30 Thread Doug Lea
Kurt's initial post did not make it to concurrency-interest. At this point, it is probably least confusing if interested readers who aren't on core-libs-dev follow this on archives: http://mail.openjdk.java.net/mailman/listinfo/core-libs-dev On 05/30/2018 01:36 PM, Martin Buchholz wrote: >

Re: Durations in existing JDK APIs

2018-05-30 Thread Stephen Colebourne
On 30 May 2018 at 18:15, Kurt Alfred Kluever wrote: > 1. Rename ALL existing unitless primitive method parameters to include > their time unit. This seems like a simple win. AFAIK, parameter names can be changed freely in the JDK. > 2. Add a java.time overload to some APIs ... > Note that new

Re: Durations in existing JDK APIs

2018-05-30 Thread Stephen Colebourne
On 30 May 2018 at 18:36, Martin Buchholz wrote: > Stephen/Doug: is there any reason we didn't add conversions between Duration > and TimeUnit when we added conversions to ChronoUnit? I don't remember the idea being discussed. The proposed implementation seems reasonable. thanks Stephen >

Re: Durations in existing JDK APIs

2018-05-30 Thread Martin Buchholz
Obvious progress would seem to be more conversion methods. Conversion code tends to be annoying/errorprone because of having to deal with overflow. Stephen/Doug: is there any reason we didn't add conversions between Duration and TimeUnit when we added conversions to ChronoUnit? Here's a