From the course: Java EE: Design Patterns and Architecture

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Asynchronous observer

Asynchronous observer

From the course: Java EE: Design Patterns and Architecture

Start my 1-month free trial

Asynchronous observer

- [Instructor] By default events are synchronous. However, in CDI 2.0 they introduced asynchronous processing of events. There is a new firing method that supports this feature called fireAsync, and a corresponding observer annotation observes async. The events are observed asynchronously and in separate threads so no priority can logically be set. So in the custom endpoint the method becomes fireAsync, and likewise here, and the corresponding observer, so if we go into our CustomerService, becomes like so, but we must remove the priority as this no longer works, and async here as well. Asynchronous and synchronous observers operate independently from each other. So an asynchronous firing of an event cannot be observed by a parameter annotated observers and vice versa. Notification options can be set on the asynchronous firing event. There's allowed a specification of a thread pool for that observer. So I'm going to go down to my asynchronous event here, and I'm going to add some…

Contents