Beginning Jakarta EE by Peter Späth

Beginning Jakarta EE by Peter Späth

Author:Peter Späth
Language: eng
Format: epub
ISBN: 9781484250792
Publisher: Apress


// Simulate some long-running calculation

try {

Thread.sleep(2000);

} catch (InterruptedException e) {

}

return new AsyncResult<String>(

"Hi from tellMeLater()");

}

}

This example EJB uses the no-interface method, but asynchronous invocation works for local and remote interfaces as well. The AsyncResult is a convenience class that allows for the easy creation of a Future object. This Future object will not really be exposed to the client; its main purpose is to obey the method signature. The Future returned to the client will instead be transparently created by the EJB container.

On the EJB client side you invoke the EJB as usual and handle the Future you received from the EJB invocation as you are used to from the JRE concurrency API, as follows: ...

@EJB

private SomeEjb someEjb;

...

Future<String> f = someEjb.tellMeLater();

try {

// Example only: block until the result

// is available:

String s = f.get();

System.err.println(s);

} catch (Exception e) {

e.printStackTrace(System.err);

}



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.