Definitely one of the most interesting talks this year at Devoxx was the one detailing all the new changes in the JEE landscape part of the next major specification upgrade JEE7. The talk was presented by Arun Gupta (@arungupta) and Antonio Goncalves (@agoncal). In this blogpost I’ll try to give an overview of the most important changes and additions in JEE7.
A lot of the specs got an overhaul of some sorts and there are also some new specs introduced. The picture below gives an overview.
A common theme in the updated specs is the introduction of CDI annotations (CDI was introduced in JEE6). CDI itself also has a new minor version upgrade of the spec. The most important change there is that the beans.xml file is no longer mandatory to turn a class into a CDI bean. Also a lot of standard default resources have been defined (like java:comp/DefaultJMSConnectionFactory). I’ll try to summarise the most interesting changes and additions.
One common pitfall in JEE before version 7 was the use of Threads. The use of user threads in JEE programming is considered a really bad practice, because thread management should be handled by the container. To standardise multithreading in a JEE application the Concurrency API is introduced.
With the help of the ManagedExecutorService and ManagedExecutorScheduledService (scheduled) jobs can be run asynchronously in a separate thread. Both services can be injected by using annotations. The ManagedThreadFactory can also be injected and provides a means to get a handle on a factory class for the creation of container managed threads.
Some powerful new features have been added to the specs. Schema generation, a feature that’s been present in Hibernate for a long time has been standardised and added to the JPA specs. It’s also possible to define indexes now by making use of the @Index annotation. Stored procedures can now be defined and called by using the @NamedStoredProcedureQuery annotation. Finally for conversion between a database type and a Java type a converter class can be defined annotated with the @Converter annotation.
For the first time in many a year the JMS specs sees a major overhaul. In the past JMS programming required a lot of boiler plating. This has been addressed in the new version of the spec. The API has been simplified and now makes heavy use of method chaining. Exceptions have been converted to Runtime Exceptions also simplifying and shortening JMS processing code. The Autocloseable interface furthermore reduces boilerplating. And last but not least connection factories and destinations (queues/topics) can now be defined programmatically using annotations (@JMSConnectionFactoryDefinition, @JMSDestinationDefinition).
Similar to the JAXP specification for XML processing the JSON-P spec provides an abstraction layer for JSON processing. There are classes which provide builder functionality for creating a JsonObject in Java (similar to DOM building for XML) and there is a JsonParser class (similar to SAX). It is expected that in a future version of JEE a JSON-B spec will arise (similar to JAXB) which standardises Java to JSON binding.
Heavily borrowing from Spring Batch (actually the Spring guys contributed a lot to the spec) the Batch 1.0 specification standardises batch processing in JEE. Batch steps, jobs, flows and listeners are all orchestrated in XML. Standard interfaces like ItemReader, ItemProcessor and ItemWriter and abstract classes are available for implementing the building blocks in a batch job.
Other important changes
- Bean Validation 1.1
- Method Validation: parameters and return values can be annotated with validators, which is a great way to further clarify the contract of a class;
- Interceptor 1.2
- Interceptors are used for crosscutting concerns like logging and can now be associated with constructors by using the @AroundConstruct annotation;
- JTA 1.2
- Transaction management is now also possible on Managed Beans with the help of the new @Transactional annotation. This means that Managed Beans become almost as powerful as EJB’s. The biggest difference being that the latter can be called remotely. It is expected that EJB’s will disappear in some future EE version and that their role will be taken over by CDI Managed Beans;
- EJB 3.2
- EJB Lite beans now support asynchronous invocations by using the @Asynchronous annotation on methods;
- Websockets 1.0
- New specification which standardises the highly popular Websockets protocol providing full-duplex bi-directional communication over a single TCP connection;
- EL 3.0
- ELProcessor class can also be used in a JSE environment;
- JSF 2.2
- New faces flow similar to task flows in ADF;
- File Upload component has been added;
- JAX-RS 2.0:
- New client API for consuming REST services also supporting asynchronous invocations;
- Message Filters and Interceptors have been added to the spec
- JavaMail 1.5
- A new @MailSessionDefinition annotation has been added for defining a mail session.
All in all some powerful features have been introduced along with some completely new and highly anticipated specifications.
You can find the slides for the Devoxx presentation “Java EE 7: What’s New in the Java EE platform” on Slideshare. The Java JEE7 code samples are on Github.Devoxx 2013 - What's new in the Java EE Platform,