Package org.eclipse.jetty.util.thread
Class ThreadPoolBudget
- java.lang.Object
-
- org.eclipse.jetty.util.thread.ThreadPoolBudget
-
@ManagedObject public class ThreadPoolBudget extends java.lang.Object
A budget of required thread usage, used to warn or error for insufficient configured threads.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
ThreadPoolBudget.Lease
class
ThreadPoolBudget.Leased
An allocation of threads
-
Field Summary
Fields Modifier and Type Field Description private java.util.Set<ThreadPoolBudget.Leased>
leases
private static Logger
LOG
private static ThreadPoolBudget.Lease
NOOP_LEASE
private ThreadPool.SizedThreadPool
pool
private int
warnAt
private java.util.concurrent.atomic.AtomicBoolean
warned
-
Constructor Summary
Constructors Constructor Description ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
Construct a budget for a SizedThreadPool.ThreadPoolBudget(ThreadPool.SizedThreadPool pool, int warnAt)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
check(int maxThreads)
Checks leases against the given number ofmaxThreads
.int
getLeasedThreads()
ThreadPool.SizedThreadPool
getSizedThreadPool()
static ThreadPoolBudget.Lease
leaseFrom(java.util.concurrent.Executor executor, java.lang.Object leasee, int threads)
ThreadPoolBudget.Lease
leaseTo(java.lang.Object leasee, int threads)
private void
printInfoOnLeases()
void
reset()
-
-
-
Field Detail
-
LOG
private static final Logger LOG
-
NOOP_LEASE
private static final ThreadPoolBudget.Lease NOOP_LEASE
-
leases
private final java.util.Set<ThreadPoolBudget.Leased> leases
-
warned
private final java.util.concurrent.atomic.AtomicBoolean warned
-
pool
private final ThreadPool.SizedThreadPool pool
-
warnAt
private final int warnAt
-
-
Constructor Detail
-
ThreadPoolBudget
public ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
Construct a budget for a SizedThreadPool.- Parameters:
pool
- The pool to budget thread allocation for.
-
ThreadPoolBudget
@Deprecated public ThreadPoolBudget(ThreadPool.SizedThreadPool pool, int warnAt)
Deprecated.- Parameters:
pool
- The pool to budget thread allocation for.warnAt
- The level of free threads at which a warning is generated.
-
-
Method Detail
-
getSizedThreadPool
public ThreadPool.SizedThreadPool getSizedThreadPool()
-
getLeasedThreads
@ManagedAttribute("the number of threads leased to components") public int getLeasedThreads()
-
reset
public void reset()
-
leaseTo
public ThreadPoolBudget.Lease leaseTo(java.lang.Object leasee, int threads)
-
check
public boolean check(int maxThreads) throws java.lang.IllegalStateException
Checks leases against the given number of
maxThreads
.- Parameters:
maxThreads
- A proposed change to the maximum threads to check.- Returns:
- true if passes check, false if otherwise (see logs for details)
- Throws:
java.lang.IllegalStateException
- if insufficient threads are configured.
-
printInfoOnLeases
private void printInfoOnLeases()
-
leaseFrom
public static ThreadPoolBudget.Lease leaseFrom(java.util.concurrent.Executor executor, java.lang.Object leasee, int threads)
-
-