From 118652e985b4486b5427654a02b70dcbea9255bb Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 27 Apr 2017 10:57:37 +0200 Subject: [PATCH] Issue #1507 --- .../jetty/util/RolloverFileOutputStream.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java index 401ccd0aff0..f4db2930bed 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/RolloverFileOutputStream.java @@ -175,9 +175,12 @@ public class RolloverFileOutputStream extends FilterOutputStream if (__rollover==null) __rollover=new Timer(RolloverFileOutputStream.class.getName(),true); - midnight = toMidnight(ZonedDateTime.now(), zone.toZoneId()); + ZonedDateTime now = ZonedDateTime.now(zone.toZoneId()); + midnight = toMidnight(now, zone.toZoneId()); + while (midnight.isBefore(now)) + midnight = nextMidnight(midnight); - scheduleNextRollover(); + scheduleNextRollover(now); } } @@ -205,11 +208,11 @@ public class RolloverFileOutputStream extends FilterOutputStream return dateTime.toLocalDate().plus(1, ChronoUnit.DAYS).atStartOfDay(dateTime.getZone()); } - private void scheduleNextRollover() + private void scheduleNextRollover(ZonedDateTime now) { _rollTask = new RollTask(); midnight = nextMidnight(midnight); - __rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - System.currentTimeMillis()); + __rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - now.toInstant().toEpochMilli()); } /* ------------------------------------------------------------ */ @@ -276,11 +279,10 @@ public class RolloverFileOutputStream extends FilterOutputStream } /* ------------------------------------------------------------ */ - private void removeOldFiles() + private void removeOldFiles(ZonedDateTime now) { if (_retainDays>0) { - ZonedDateTime now = ZonedDateTime.now(this.midnight.getZone()); now.minus(_retainDays, ChronoUnit.DAYS); long expired = now.toInstant().toEpochMilli(); @@ -354,9 +356,10 @@ public class RolloverFileOutputStream extends FilterOutputStream { try { + ZonedDateTime now = ZonedDateTime.now(midnight.getZone()); RolloverFileOutputStream.this.setFile(); - RolloverFileOutputStream.this.scheduleNextRollover(); - RolloverFileOutputStream.this.removeOldFiles(); + RolloverFileOutputStream.this.scheduleNextRollover(now); + RolloverFileOutputStream.this.removeOldFiles(now); } catch(Throwable t) {