From the course: Java EE: Contexts and Dependency Injection

Unlock the full course today

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

Async events

Async events

From the course: Java EE: Contexts and Dependency Injection

Start my 1-month free trial

Async events

- [Instructor] Asynchronous events are fired in separate threads. So, each event gets its own thread, and because of this if an exception is found in subscriber, no other subscriber is affected. So, let's see this in action. I'm going to change the fire method, first of all, in the stock observer. So, I now need to change this from a fire to fire async. And, I also need to change the observers. So, let's go to the Sell Trading Bot, and I need to change this annotation to the async version. So, like so. And, I also need to do the same thing in the other bots. I'm just going to change this to also to async, and I'm also going to change it in this one, as well. If you want to use asynchronous subscribers, you need to first change the event to fire async, and then change the observer annotation to observes async. Now, let's add a Null Pointer Exception in our Sell Trading Bot, like we did previously. So, I'm just going to throw a new Null Pointer Exception, like so. And, what I'm going to…

Contents