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 |
---|---|
(package private) java.util.Set<ThreadPoolBudget.Leased> |
allocations |
(package private) java.util.Set<ThreadPoolBudget.Leased> |
info |
(package private) static Logger |
LOG |
private static ThreadPoolBudget.Lease |
NOOP_LEASE |
(package private) ThreadPool.SizedThreadPool |
pool |
(package private) int |
warnAt |
(package private) java.util.concurrent.atomic.AtomicBoolean |
warned |
Constructor and Description |
---|
ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
Construct a budget for a SizedThreadPool, with the warning level set by heuristic.
|
ThreadPoolBudget(ThreadPool.SizedThreadPool pool,
int warnAt) |
Modifier and Type | Method and Description |
---|---|
void |
check()
Check registered allocations against the budget.
|
ThreadPool.SizedThreadPool |
getSizedThreadPool() |
private void |
infoOnLeases() |
static ThreadPoolBudget.Lease |
leaseFrom(java.util.concurrent.Executor executor,
java.lang.Object leasee,
int threads) |
ThreadPoolBudget.Lease |
leaseTo(java.lang.Object leasee,
int threads) |
void |
reset() |
static final Logger LOG
private static final ThreadPoolBudget.Lease NOOP_LEASE
final ThreadPool.SizedThreadPool pool
final java.util.Set<ThreadPoolBudget.Leased> allocations
final java.util.Set<ThreadPoolBudget.Leased> info
final java.util.concurrent.atomic.AtomicBoolean warned
final int warnAt
public ThreadPoolBudget(ThreadPool.SizedThreadPool pool)
pool
- The pool to budget thread allocation for.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 void check() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if insufficient threads are configured.private void infoOnLeases()
public static ThreadPoolBudget.Lease leaseFrom(java.util.concurrent.Executor executor, java.lang.Object leasee, int threads)