To use deferred, you first need to define a class containing the code that you want to run:
class MyDeferred implements DeferredTask { @Override public void run() {
Like any other serializable class, you can have local resources that store relevant information about the task. Then, to start the task, create an instance of your class and pass it to the task queue API:
MyDeferred task = new MyDeferred(); // Set instance variables etc as you wish Queue queue = QueueFactory.getDefaultQueue(); queue.add(withPayload(task));
You can even use anonymous inner classes for your tasks, but beware of the caveats described in the note here .
Nick johnson
source share