public class ThreadPoolBudget
extends java.lang.Object
A budget of required thread usage, used to warn or error for insufficient configured threads.
Modifier and Type | Class and Description |
---|---|
static interface |
ThreadPoolBudget.Lease |
class |
ThreadPoolBudget.Leased
An allocation of threads
|
Modifier and Type | Field and Description |
---|---|
private java.util.Set<ThreadPoolBudget.Leased> |
leases |
(package 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 and Description |
---|
ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
Construct a budget for a SizedThreadPool.
|
ThreadPoolBudget(ThreadPool.SizedThreadPool pool,
int warnAt)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
boolean |
check(int maxThreads)
Checks leases against the given number of
maxThreads . |
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() |
static final Logger LOG
private static final ThreadPoolBudget.Lease NOOP_LEASE
private final java.util.Set<ThreadPoolBudget.Leased> leases
private final java.util.concurrent.atomic.AtomicBoolean warned
private final ThreadPool.SizedThreadPool pool
private final int warnAt
public ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
pool
- The pool to budget thread allocation for.@Deprecated public ThreadPoolBudget(ThreadPool.SizedThreadPool pool, int warnAt)
pool
- The pool to budget thread allocation for.warnAt
- The level of free threads at which a warning is generated.public ThreadPool.SizedThreadPool getSizedThreadPool()
public void reset()
public ThreadPoolBudget.Lease leaseTo(java.lang.Object leasee, int threads)
public boolean check(int maxThreads) throws java.lang.IllegalStateException
Checks leases against the given number of maxThreads
.
maxThreads
- A proposed change to the maximum threads to check.java.lang.IllegalStateException
- if insufficient threads are configured.private void printInfoOnLeases()
public static ThreadPoolBudget.Lease leaseFrom(java.util.concurrent.Executor executor, java.lang.Object leasee, int threads)