Velai Threads for Java is an open source framework to simplify the creation of threaded code within Java applications.
Features
Velai Threads for Java makes use of annotations and reflection to enable you to easily support all of the features below, with minimal coding effort.
CancellationRequest the task to cancel. Check for cancellation requests. |
PausingPause a task in the middle of its operation and then unpause when you wish. |
TimingKnow how long a task has taken to execute. Know how long ago a task completed. |
ExceptionsYou don't have to write any special code to record exceptions thrown by threads. |
StateMonitor the state of any task. Attach listeners to state changes. |
ExtendUses interfaces and annotations. Subclass your tasks without Velai getting in the way. |
PatternsOut-of-box support for barrier, parallel and sequential patterns. |
Example
Check out the simple example below. That is all you need to do to enable out-of-the-box support for:
- executing it synchronously (in the same thread) or asynchronously (in a thread of its own)
- task cancellation
- pausing and unpausing the task
- timing how long it takes to execute
- monitoring its state
- and so many other things with only a small amount of additional code
public class MyTask implements Callable<Void> { @Context private ExecutionContext execution; public Void call() throws Exception { while (!execution.isCancellationRequested(true)) { // do stuff } return null; } }