Issue #1469 - conforming to java.util.Timer quirks

This commit is contained in:
Joakim Erdfelt 2017-04-13 09:07:26 -07:00
parent 6a10b4272b
commit 399ff337c8
1 changed files with 8 additions and 9 deletions

View File

@ -175,8 +175,6 @@ public class RolloverFileOutputStream extends FilterOutputStream
if (__rollover==null)
__rollover=new Timer(RolloverFileOutputStream.class.getName(),true);
_rollTask=new RollTask();
midnight = toMidnight(ZonedDateTime.now(), zone.toZoneId());
scheduleNextRollover();
@ -204,14 +202,12 @@ public class RolloverFileOutputStream extends FilterOutputStream
public static ZonedDateTime nextMidnight(ZonedDateTime dateTime)
{
// Increment to next day.
// Using Calendar.add(DAY, 1) takes in account Daylights Savings
// differences, and still maintains the "midnight" settings for
// Hour, Minute, Second, Milliseconds
return dateTime.toLocalDate().plus(1, ChronoUnit.DAYS).atStartOfDay(dateTime.getZone());
}
private void scheduleNextRollover()
{
_rollTask = new RollTask();
midnight = nextMidnight(midnight);
__rollover.schedule(_rollTask,midnight.toInstant().toEpochMilli() - System.currentTimeMillis());
}
@ -342,8 +338,11 @@ public class RolloverFileOutputStream extends FilterOutputStream
out=null;
_file=null;
}
_rollTask.cancel();
if (_rollTask != null)
{
_rollTask.cancel();
}
}
}
@ -359,10 +358,10 @@ public class RolloverFileOutputStream extends FilterOutputStream
RolloverFileOutputStream.this.scheduleNextRollover();
RolloverFileOutputStream.this.removeOldFiles();
}
catch(IOException e)
catch(Throwable t)
{
// Cannot log this exception to a LOG, as RolloverFOS can be used by logging
e.printStackTrace(System.err);
t.printStackTrace(System.err);
}
}
}