Package ai.djl.serving.wlm
Class WorkerThread<I,O>
- java.lang.Object
-
- ai.djl.serving.wlm.WorkerThread<I,O>
-
- All Implemented Interfaces:
java.lang.Runnable
public final class WorkerThread<I,O> extends java.lang.Object implements java.lang.Runnable
TheWorkerThread
is the worker managed by theWorkLoadManager
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WorkerThread.Builder<I,O>
A Builder to construct aWorkerThread
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addConfigJob(WorkerJob<I,O> wj)
Adds a configuration job to this thread.static <I,O>
WorkerThread.Builder<I,O>builder(WorkerPoolConfig<I,O> wpc)
Creates a builder to build aWorkerThread
.ai.djl.Device
getDevice()
Returns the device used by the thread.long
getStartTime()
Returns the thread start time.WorkerState
getState()
Returns the worker state.WorkerPoolConfig.ThreadConfig<I,O>
getThreadType()
Returns theWorkerPoolConfig
'sWorkerPoolConfig.ThreadConfig
for this thread.int
getWorkerId()
Returns the worker thread ID.boolean
isFixPoolThread()
check if this worker is instantiate is one of the fix threads of a pool.boolean
isRunning()
Returns true if the worker thread is running.void
run()
void
shutdown(WorkerState state)
Shuts down the worker thread.
-
-
-
Method Detail
-
run
public void run()
- Specified by:
run
in interfacejava.lang.Runnable
-
getWorkerId
public int getWorkerId()
Returns the worker thread ID.- Returns:
- the worker thread ID
-
getThreadType
public WorkerPoolConfig.ThreadConfig<I,O> getThreadType()
Returns theWorkerPoolConfig
'sWorkerPoolConfig.ThreadConfig
for this thread.- Returns:
- the
WorkerPoolConfig
'sWorkerPoolConfig.ThreadConfig
for this thread
-
isRunning
public boolean isRunning()
Returns true if the worker thread is running.- Returns:
- true if the worker thread is running
-
getDevice
public ai.djl.Device getDevice()
Returns the device used by the thread.- Returns:
- the device used by the thread
-
getStartTime
public long getStartTime()
Returns the thread start time.- Returns:
- the thread start time
-
getState
public WorkerState getState()
Returns the worker state.- Returns:
- the worker state
-
shutdown
public void shutdown(WorkerState state)
Shuts down the worker thread.- Parameters:
state
- the state to set the thread to
-
addConfigJob
public void addConfigJob(WorkerJob<I,O> wj)
Adds a configuration job to this thread.- Parameters:
wj
- the configuration job to add
-
isFixPoolThread
public boolean isFixPoolThread()
check if this worker is instantiate is one of the fix threads of a pool. fix threads are not automatically scales down, so they are candidate for down scaling when minWorker/maxWorker size of a model changes.- Returns:
- the fixPoolThread
-
builder
public static <I,O> WorkerThread.Builder<I,O> builder(WorkerPoolConfig<I,O> wpc)
Creates a builder to build aWorkerThread
.- Type Parameters:
I
- the workerPoolConfig input classO
- the workerPoolConfig output class- Parameters:
wpc
- theWorkerPoolConfig
the thread will be responsible for- Returns:
- a new builder
-
-