Java Reference
In-Depth Information
Let's take a look at an asynchronous method that includes a
void
return type. The following method has been
excerpted from the
org.javaee7.jpa.session.JobsSession
class, and the asynchronous task involves querying the
Jobs
entity and returning all results:
@Asynchronous
public void retrieveJobs(){
Query qry = em.createQuery("select j from Jobs j");
List<Jobs> jobs = qry.getResultList();
for (Jobs job:jobs){
System.out.println(job.getTitle());
}
}
The following is an example of an asynchronous method that returns a result. The same method that was used
in the previous example has been altered to return a Boolean value to indicate whether any
Jobs
entities exist.
@Asynchronous
public Future<Boolean> obtainJobListing(){
Query qry = em.createQuery("select j from Jobs j");
List<Jobs> jobs = qry.getResultList();
if(jobs.size() > 0){
this.jobList = jobs;
return new AsyncResult<Boolean>(true);
} else {
return new AsyncResult<Boolean>(false);
}
}
Another new feature for EJB Lite is that it is now possible to specify a nonpersistent timer service. To specify
a timer as nonpersistent, specify the
persistent
attribute with a value of
false
for the
@Schedule
annotation.
The following schedule-based timer demonstrates a nonpersistent timer designation:
@Schedule(minute="*/1", hour="*", persistent=false)
public void scheduledTimerExample(){
System.out.println("This timer will go off every minute");
}
Optional Features
As the EJB specification grows and matures, a number of older API features are no longer required. As a result, it is
prudent to make such features optional in order to maintain backward compatibility. The following features have
been made optional in the EJB 3.2 release:
•
Entity bean component contract for CMP and BMP
•
Client view of an EJB 2.1 and earlier entity bean
•
EJBQL
•
JAX-RPC web service endpoints and client view
Remember, these features are optional because they represent older APIs being phased out. You may want to stay
away from these APIs when writing new code.