play.jobs

## Class Job<V>

- java.lang.Object
- - play.Invoker.Invocation
  - - play.jobs.Job<V>

Type Parameters:
  `V` - The job result type (if any)

All Implemented Interfaces:
  java.lang.Runnable, java.util.concurrent.Callable<V>

    public class Job<V>
    extends Invoker.Invocation
    implements java.util.concurrent.Callable<V>

A job is an asynchronously executed unit of work

### Field Summary

Fields
`protected java.util.concurrent.ExecutorService` `executor`
`static java.lang.String` `invocationType`
`protected java.lang.Throwable` `lastException`
`protected long` `lastRun`
`protected boolean` `wasError`

### Constructor Summary

Constructors
Constructor and Description
`Job()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `_finally()` Things to do in all cases after the invocation.
`F.Promise<V>` `afterRequest()` If is called in a 'HttpRequest' invocation context, waits until request is served and schedules job then.
`V` `call()`
`void` `doJob()` Here you do the job
`V` `doJobWithResult()` Here you do the job and return a result
`void` `every(int seconds)` Run this job every n seconds
`void` `every(java.lang.String delay)` Run this job every n seconds
`void` `execute()` Override this method
`Invoker.InvocationContext` `getInvocationContext()`
`F.Promise<V>` `in(int seconds)` Start this job in several seconds
`F.Promise<V>` `in(java.lang.String delay)` Start this job in several seconds
`F.Promise<V>` `now()` Start this job now (well ASAP)
`void` `onException(java.lang.Throwable e)` Things to do if the Invocation code thrown an exception
`void` `run()` It's time to execute.
`java.lang.String` `toString()`

### Methods inherited from class play.Invoker.Invocation

`after, before, init, onSuccess, preInit, suspend`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Field Detail

#### invocationType

    public static final java.lang.String invocationType

See Also:
  Constant Field Values

#### executor

    protected java.util.concurrent.ExecutorService executor

#### lastRun

    protected long lastRun

#### wasError

    protected boolean wasError

#### lastException

    protected java.lang.Throwable lastException

### Constructor Detail

#### Job

    public Job()

### Method Detail

#### getInvocationContext

    public Invoker.InvocationContext getInvocationContext()

Specified by:
  `getInvocationContext` in class `Invoker.Invocation`

#### doJob

    public void doJob()
               throws java.lang.Exception

Here you do the job

Throws:
  `java.lang.Exception` - if problems occurred

#### doJobWithResult

    public V doJobWithResult()
                      throws java.lang.Exception

Here you do the job and return a result

Returns:
  The job result
Throws:
  `java.lang.Exception` - if problems occurred

#### execute

    public void execute()
                 throws java.lang.Exception

Description copied from class: `Invoker.Invocation`
Override this method

Specified by:
  `execute` in class `Invoker.Invocation`
Throws:
  `java.lang.Exception` - Thrown if Invocation encounters any problems

#### now

    public F.Promise<V> now()

Start this job now (well ASAP)

Returns:
  the job completion

#### afterRequest

    public F.Promise<V> afterRequest()

If is called in a 'HttpRequest' invocation context, waits until request is served and schedules job then. Otherwise is the same as now(); If you want to schedule a job to run after some other job completes, wait till a promise redeems of just override first Job's call() to schedule the second one.

Returns:
  the job completion

#### in

    public F.Promise<V> in(java.lang.String delay)

Start this job in several seconds

Parameters:
  `delay` - time in seconds
Returns:
  the job completion

#### in

    public F.Promise<V> in(int seconds)

Start this job in several seconds

Parameters:
  `seconds` - time in seconds
Returns:
  the job completion

#### every

    public void every(java.lang.String delay)

Run this job every n seconds

Parameters:
  `delay` - time in seconds

#### every

    public void every(int seconds)

Run this job every n seconds

Parameters:
  `seconds` - time in seconds

#### onException

    public void onException(java.lang.Throwable e)

Description copied from class: `Invoker.Invocation`
Things to do if the Invocation code thrown an exception

Overrides:
  `onException` in class `Invoker.Invocation`
Parameters:
  `e` - The exception

#### run

    public void run()

Description copied from class: `Invoker.Invocation`
It's time to execute.

Specified by:
  `run` in interface `java.lang.Runnable`
Overrides:
  `run` in class `Invoker.Invocation`

#### call

    public V call()

Specified by:
  `call` in interface `java.util.concurrent.Callable<V>`

#### _finally

    public void _finally()

Description copied from class: `Invoker.Invocation`
Things to do in all cases after the invocation.

Overrides:
  `_finally` in class `Invoker.Invocation`

#### toString

    public java.lang.String toString()

Overrides:
  `toString` in class `java.lang.Object`