diff --git a/CHANGELOG.md b/CHANGELOG.md index a69ace0d..29ffa7e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Splunk Logging for Java Changelog +## Version 1.6.1 + +* TcpAppender performance improvement, prevents 100% CPU usage [#85](https://github.com/splunk/splunk-library-javalogging/pull/85). + ## Version 1.6.0 * Changed messagedMimeType metadata property to messageFormat * Fixes unit tests, and performance issues diff --git a/README.md b/README.md index d8e3d7a4..ae74b43f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Splunk Logging for Java -#### Version 1.6.0 +#### Version 1.6.1 This project provides utilities to easily log data using Splunk's recommended best practices to any supported logger, using any of the three major Java diff --git a/pom.xml b/pom.xml index 9bfb6cdc..f487beb7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.splunk.logging splunk-library-javalogging - 1.6.0 + 1.6.1 jar Splunk Logging for Java diff --git a/src/main/java/com/splunk/logging/TcpAppender.java b/src/main/java/com/splunk/logging/TcpAppender.java index 7e41abe5..980019ae 100644 --- a/src/main/java/com/splunk/logging/TcpAppender.java +++ b/src/main/java/com/splunk/logging/TcpAppender.java @@ -129,23 +129,7 @@ public void run() { } catch (InterruptedException ex) { // Exiting. } - addInfo("shutting down"); - - // The thread pool used by the default executor spawns non-daemon - // threads that prevent appropriate termination of the program. - // - // To ensure that the program eventually terminates, we reconfigure the - // shared executor service to spin down to zero worker threads when no - // work is left. - // - // Can't do this work in the constructor because the context isn't yet set. - // - // It is possible for someone else to replace the executor, so only - // perform this special logic if it looks like we still have the default executor. - ExecutorService service = this.getContext().getExecutorService(); - if (service instanceof ThreadPoolExecutor) { - ((ThreadPoolExecutor) service).setCorePoolSize(0); - } + addInfo("exiting"); } private SocketConnector initSocketConnector() { @@ -252,7 +236,15 @@ public void start() { // Dispatch this instance of the appender. if (!errorPresent) { queue = queueSize <= 0 ? new SynchronousQueue() : new ArrayBlockingQueue(queueSize); - executor = Executors.newSingleThreadExecutor(); + ThreadFactory factory = new ThreadFactory() { + @Override + public Thread newThread(Runnable r) { + Thread t = new Thread(r, "splunk-tcp-appender"); + t.setDaemon(true); + return t; + } + }; + executor = Executors.newSingleThreadExecutor(factory); executor.execute(this); }