Skip to content

Commit

Permalink
Issues/#1271 client cpu (#1272)
Browse files Browse the repository at this point in the history
* Patch for OpenJDK 100% CPU usage bug

Signed-off-by: Bart Hanssens <bart.hanssens@bosa.fgov.be>

* Make it selectable by system property

Signed-off-by: Bart Hanssens <bart.hanssens@bosa.fgov.be>

* Made variable final static + added link to description of bug

* Changed property name

Signed-off-by: Bart Hanssens <bart.hanssens@bosa.fgov.be>
  • Loading branch information
barthanssens committed Feb 4, 2019
1 parent 274e779 commit 7efafb8
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
* @author James Leigh
*/
public class SharedHttpClientSessionManager implements HttpClientSessionManager, HttpClientDependent {
/**
* FIXME: issue #1271, workaround for OpenJDK 8 bug.
* ScheduledThreadPoolExecutor with 0 core threads may cause 100% CPU usage.
* Using 1 core thread instead of 0 (default) fixes the problem but wastes some resources.
*
* @see <a href="https://bugs.openjdk.java.net/browse/JDK-8129861">JDK-8129861</a>
*/
private static final int cores =
(System.getProperty("org.eclipse.rdf4j.client.executors.jdkbug") != null) ? 1 : 0;
/**/

private static final AtomicLong threadCount = new AtomicLong();

Expand All @@ -56,7 +66,7 @@ public class SharedHttpClientSessionManager implements HttpClientSessionManager,

public SharedHttpClientSessionManager() {
final ThreadFactory backingThreadFactory = Executors.defaultThreadFactory();
this.executor = Executors.newScheduledThreadPool(0, new ThreadFactory() {
this.executor = Executors.newScheduledThreadPool(cores, new ThreadFactory() {

public Thread newThread(Runnable runnable) {
Thread thread = backingThreadFactory.newThread(runnable);
Expand Down

0 comments on commit 7efafb8

Please sign in to comment.