Skip to Content
Java EE 8 Application Development
book

Java EE 8 Application Development

by David R. Heffelfinger
December 2017
Intermediate to advanced
372 pages
8h 46m
English
Packt Publishing
Content preview from Java EE 8 Application Development

Event ordering

Another new feature introduced in CDI 2.0 is the ability to specify in which order our observer methods handle CDI events. This can be accomplished via the @Priority annotation, as illustrated in the following example:

import javax.annotation.Priority; 
import javax.enterprise.context.SessionScoped; 
import javax.enterprise.event.Observes; 
import javax.interceptor.Interceptor; 
 
@SessionScoped 
public class EventHandler{ 
    void handleIt (      @Observes @Priority(Interceptor.Priority.APPLICATION)       MyEvent me){ 
    //handle the event 
  } 
} 

The @Priority annotation takes an argument of type int. This argument specifies the priority for the observer method. The highest priority is defined by the APPLICATION constant defined in the Interceptor.Priority ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java EE 8 Development with Eclipse

Java EE 8 Development with Eclipse

Ram Kulkarni
Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Beginning EJB in Java EE 8: Building Applications with Enterprise JavaBeans

Jonathan Wetherbee, Massimo Nardone, Chirag Rathod, Raghu Kodali

Publisher Resources

ISBN: 9781788293679Supplemental Content