April 2018
Intermediate to advanced
382 pages
10h 11m
English
The magic happens in the AsyncTask class, where we will first take a look at the performLookups method:
private void performLookups() throws NamingException{ Context ctx = new InitialContext(); userTransaction = (UserTransaction) ctx.lookup("java:comp/UserTransaction"); userBean = (UserBean) ctx.lookup("java:global/ ch09-async-transaction/UserBean"); }
It will give you the instances of both UserTransaction and UserBean from the application server. Then you can relax and rely on the things already instantiated for you.
As our task implements a Callabe<V> object that it needs to implement the call() method:
@Override public User call() throws Exception { performLookups(); try { userTransaction.begin(); User user = userBean.getUser(); ...Read now
Unlock full access