Class SimpleTaskWorkManager
- java.lang.Object
- org.springframework.jca.work.SimpleTaskWorkManager
- All Implemented Interfaces:
WorkManager
public class SimpleTaskWorkManager extends Object implements WorkManager
Simple JCA 1.5WorkManager
implementation that delegates to a SpringTaskExecutor
. Provides simple task execution including start timeouts, but without support for a JCA ExecutionContext (i.e. without support for imported transactions).Uses a
SyncTaskExecutor
fordoWork(javax.resource.spi.work.Work)
calls and aSimpleAsyncTaskExecutor
forstartWork(javax.resource.spi.work.Work)
andscheduleWork(javax.resource.spi.work.Work)
calls, by default. These default task executors can be overridden through configuration.NOTE: This WorkManager does not provide thread pooling by default! Specify a
ThreadPoolTaskExecutor
(or any other thread-pooling TaskExecutor) as "asyncTaskExecutor" in order to achieve actual thread pooling.This WorkManager automatically detects a specified
AsyncTaskExecutor
implementation and uses its extended timeout functionality where appropriate. JCA WorkListeners are fully supported in any case.- Since:
- 2.0.3
- Author:
- Juergen Hoeller
- See Also:
setSyncTaskExecutor(org.springframework.core.task.TaskExecutor)
,setAsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor)
Field Summary
Fields inherited from interface javax.resource.spi.work.WorkManager
IMMEDIATE, INDEFINITE, UNKNOWN
Constructor Summary
Constructors Constructor Description SimpleTaskWorkManager()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
doWork(Work work)
void
doWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
protected long
executeWork(TaskExecutor taskExecutor, Work work, long startTimeout, boolean blockUntilStarted, ExecutionContext executionContext, WorkListener workListener)
Execute the given Work on the specified TaskExecutor.void
scheduleWork(Work work)
void
scheduleWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
void
setAsyncTaskExecutor(AsyncTaskExecutor asyncTaskExecutor)
Specify the TaskExecutor to use for asynchronous work execution (i.e.void
setSyncTaskExecutor(TaskExecutor syncTaskExecutor)
Specify the TaskExecutor to use for synchronous work execution (i.e.long
startWork(Work work)
long
startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener)
Constructor Detail
SimpleTaskWorkManager
public SimpleTaskWorkManager()
Method Detail
setSyncTaskExecutor
public void setSyncTaskExecutor(TaskExecutor syncTaskExecutor)
Specify the TaskExecutor to use for synchronous work execution (i.e.doWork(javax.resource.spi.work.Work)
calls).Default is a
SyncTaskExecutor
.
setAsyncTaskExecutor
public void setAsyncTaskExecutor(AsyncTaskExecutor asyncTaskExecutor)
Specify the TaskExecutor to use for asynchronous work execution (i.e.startWork(javax.resource.spi.work.Work)
andscheduleWork(javax.resource.spi.work.Work)
calls).This will typically (but not necessarily) be an
AsyncTaskExecutor
implementation. Default is aSimpleAsyncTaskExecutor
.
doWork
public void doWork(Work work) throws WorkException
- Specified by:
doWork
in interfaceWorkManager
- Throws:
WorkException
doWork
public void doWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException
- Specified by:
doWork
in interfaceWorkManager
- Throws:
WorkException
startWork
public long startWork(Work work) throws WorkException
- Specified by:
startWork
in interfaceWorkManager
- Throws:
WorkException
startWork
public long startWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException
- Specified by:
startWork
in interfaceWorkManager
- Throws:
WorkException
scheduleWork
public void scheduleWork(Work work) throws WorkException
- Specified by:
scheduleWork
in interfaceWorkManager
- Throws:
WorkException
scheduleWork
public void scheduleWork(Work work, long startTimeout, ExecutionContext executionContext, WorkListener workListener) throws WorkException
- Specified by:
scheduleWork
in interfaceWorkManager
- Throws:
WorkException
executeWork
protected long executeWork(TaskExecutor taskExecutor, Work work, long startTimeout, boolean blockUntilStarted, ExecutionContext executionContext, WorkListener workListener) throws WorkException
Execute the given Work on the specified TaskExecutor.- Parameters:
taskExecutor
- the TaskExecutor to usework
- the Work to executestartTimeout
- the time duration within which the Work is supposed to startblockUntilStarted
- whether to block until the Work has startedexecutionContext
- the JCA ExecutionContext for the given WorkworkListener
- the WorkListener to clal for the given Work- Returns:
- the time elapsed from Work acceptance until start of execution (or -1 if not applicable or not known)
- Throws:
WorkException
- if the TaskExecutor did not accept the Work