public class Jobs<P> extends Object
JobContext jobContext = JobContext.forMultiJob(10);
Stream<Integer> result = jobContext.forEach(1, 2, 3)
.run(p -> p * 10);
For more samples see a MultiJobTest class.https://dzone.com/articles/think-twice-using-java-8,
https://www.baeldung.com/java-completablefuture| Modifier and Type | Class and Description |
|---|---|
static class |
Jobs.JobException
An envelope for checked exceptions
|
static interface |
Jobs.UserFunction<T,R> |
| Modifier and Type | Field and Description |
|---|---|
protected static String |
REQUIRED_INPUT_TEMPLATE_MSG
Template message for an invalid input
|
protected Duration |
timeout
A timeout of a job where a default duration is the one hour
|
| Modifier | Constructor and Description |
|---|---|
protected |
Jobs(Stream<P> params,
Duration timeout) |
| Modifier and Type | Method and Description |
|---|---|
protected Stream<P> |
getParallel()
Get a parameter Stream like a parallel type
|
<R> Stream<R> |
run(Jobs.UserFunction<P,R> job)
Get of single values where all nulls are excluded
|
<R> Stream<R> |
runOfStream(Jobs.UserFunction<P,Stream<R>> job)
Get result of a Streams
|
<R> long |
runOfSum(Jobs.UserFunction<P,Integer> job)
Get a sum of job results type of
long |
Jobs<P> |
setTimeout(Duration timeout)
Set a timeout where a default duration is the one hour
|
protected static final String REQUIRED_INPUT_TEMPLATE_MSG
@Nonnull protected final Stream<P> getParallel()
public final Jobs<P> setTimeout(@Nonnull Duration timeout)
timeout - The maximum time to wait.public <R> Stream<R> run(@Nonnull Jobs.UserFunction<P,R> job)
job - Job with a simple value resultpublic <R> Stream<R> runOfStream(@Nonnull Jobs.UserFunction<P,Stream<R>> job)
job - Job with a stream resultpublic <R> long runOfSum(@Nonnull Jobs.UserFunction<P,Integer> job) throws Jobs.JobException
longjob - Job with a simple value resultJobs.JobExceptionCopyright 2015, Pavel Ponec