Repository: logging-log4j2 Updated Branches: refs/heads/master dff60e69c -> 460cf5952
Refactor a touch for reuse and customization. Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/460cf595 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/460cf595 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/460cf595 Branch: refs/heads/master Commit: 460cf5952febf7c924c73b60a39157325aba3e19 Parents: dff60e6 Author: Gary Gregory <[email protected]> Authored: Tue Jul 18 20:01:25 2017 -0700 Committer: Gary Gregory <[email protected]> Committed: Tue Jul 18 20:01:25 2017 -0700 ---------------------------------------------------------------------- .../core/config/ConfigurationScheduler.java | 22 ++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/460cf595/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java index 6ffb29d..0dea9a4 100644 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java @@ -38,9 +38,19 @@ public class ConfigurationScheduler extends AbstractLifeCycle { private static final Logger LOGGER = StatusLogger.getLogger(); private static final String SIMPLE_NAME = "Log4j2 " + ConfigurationScheduler.class.getSimpleName(); private static final int MAX_SCHEDULED_ITEMS = 5; + private ScheduledExecutorService executorService; - private int scheduledItems = 0; + private final String name; + + public ConfigurationScheduler() { + this(SIMPLE_NAME); + } + + public ConfigurationScheduler(String name) { + super(); + this.name = name; + } @Override public void start() { @@ -51,7 +61,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopping(); if (isExecutorServiceSet()) { - LOGGER.debug("{} shutting down threads in {}", SIMPLE_NAME, getExecutorService()); + LOGGER.debug("{} shutting down threads in {}", name, getExecutorService()); executorService.shutdown(); try { executorService.awaitTermination(timeout, timeUnit); @@ -79,7 +89,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { */ public void incrementScheduledItems() { if (isExecutorServiceSet()) { - LOGGER.error("{} attempted to increment scheduled items after start", SIMPLE_NAME); + LOGGER.error("{} attempted to increment scheduled items after start", name); } else { ++scheduledItems; } @@ -184,7 +194,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { private ScheduledExecutorService getExecutorService() { if (executorService == null) { if (scheduledItems > 0) { - LOGGER.debug("{} starting {} threads", SIMPLE_NAME, scheduledItems); + LOGGER.debug("{} starting {} threads", name, scheduledItems); scheduledItems = Math.min(scheduledItems, MAX_SCHEDULED_ITEMS); final ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(scheduledItems, Log4jThreadFactory.createDaemonThreadFactory("Scheduled")); @@ -193,7 +203,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { this.executorService = executor; } else { - LOGGER.debug("{}: No scheduled items", SIMPLE_NAME); + LOGGER.debug("{}: No scheduled items", name); } } return executorService; @@ -228,7 +238,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle { } runnable.run(); } catch(final Throwable ex) { - LOGGER.error("{} caught error running command", SIMPLE_NAME, ex); + LOGGER.error("{} caught error running command", name, ex); } finally { final Date fireDate = cronExpression.getNextValidTimeAfter(new Date()); final ScheduledFuture<?> future = schedule(this, nextFireInterval(fireDate), TimeUnit.MILLISECONDS);
