Skip to content

Commit

Permalink
Support setting ThreadFactory for Jetty 10, 11 and 12 (#3531)
Browse files Browse the repository at this point in the history
This PR prepares support for project loom with allowing to set a ThreadFactory for the InstrumentedQueuedThreadPool.

The constructors for the InstrumentedQueuedThreadPool are aligned with the ones from QueuedThreadPool to allow setting parameters that currently cannot be provided.
  • Loading branch information
zUniQueX authored Sep 22, 2023
1 parent f48ddce commit 2299db7
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.jetty.util.thread.QueuedThreadPool;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadFactory;

import static com.codahale.metrics.MetricRegistry.name;

Expand Down Expand Up @@ -34,6 +35,13 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
this(registry, maxThreads, minThreads, 60000);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, 60000, queue);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
Expand All @@ -46,16 +54,67 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, idleTimeout, queue, null);
this(registry, maxThreads, minThreads, idleTimeout, queue, (ThreadGroup) null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("prefix") String prefix) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, null, null, prefix);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadFactory") ThreadFactory threadFactory) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, null, threadFactory);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, threadGroup);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup) {
this(registry, maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup,
@Name("threadFactory") ThreadFactory threadFactory) {
this(registry, maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, threadFactory, null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup,
@Name("threadFactory") ThreadFactory threadFactory,
@Name("prefix") String prefix) {
super(maxThreads, minThreads, idleTimeout, queue);
super(maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, threadFactory);
this.metricRegistry = registry;
this.prefix = prefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.eclipse.jetty.util.thread.QueuedThreadPool;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ThreadFactory;

import static com.codahale.metrics.MetricRegistry.name;

Expand Down Expand Up @@ -34,6 +35,13 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
this(registry, maxThreads, minThreads, 60000);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, 60000, queue);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
Expand All @@ -46,16 +54,67 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, idleTimeout, queue, null);
this(registry, maxThreads, minThreads, idleTimeout, queue, (ThreadGroup) null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("prefix") String prefix) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, null, null, prefix);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadFactory") ThreadFactory threadFactory) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, null, threadFactory);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, threadGroup);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup) {
this(registry, maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup,
@Name("threadFactory") ThreadFactory threadFactory) {
this(registry, maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, threadFactory, null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("reservedThreads") int reservedThreads,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadGroup") ThreadGroup threadGroup,
@Name("threadFactory") ThreadFactory threadFactory,
@Name("prefix") String prefix) {
super(maxThreads, minThreads, idleTimeout, queue);
super(maxThreads, minThreads, idleTimeout, reservedThreads, queue, threadGroup, threadFactory);
this.metricRegistry = registry;
this.prefix = prefix;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue) {
this(registry, maxThreads, minThreads, idleTimeout, queue, null);
this(registry, maxThreads, minThreads, idleTimeout, queue, (ThreadGroup) null);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
@Name("maxThreads") int maxThreads,
@Name("minThreads") int minThreads,
@Name("idleTimeout") int idleTimeout,
@Name("queue") BlockingQueue<Runnable> queue,
@Name("threadFactory") ThreadFactory threadFactory) {
this(registry, maxThreads, minThreads, idleTimeout, -1, queue, null, threadFactory);
}

public InstrumentedQueuedThreadPool(@Name("registry") MetricRegistry registry,
Expand Down

0 comments on commit 2299db7

Please sign in to comment.