# Event handling in java

**URL:** <https://forum.devtalk.com/t/event-handling-in-java/104430>\
**Category:** General Dev Chat\
**Tags:** java\
**Created:** [10 April 2023 12:55 UTC](https://forum.devtalk.com/t/event-handling-in-java/104430 "2023-04-10T12:55:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![harwind](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/h/c77e96/32.png) [@harwind](https://forum.devtalk.com/u/harwind)\
**Post date:** [10 April 2023 12:55 UTC](https://forum.devtalk.com/t/event-handling-in-java/104430/1 "2023-04-10T12:55:58Z")

</div>

I’m developing a web-based application that uses Java servlets to make RPC calls.  
I’m searching for a solid technique to dispatch and handle server events. With a PHP application, I’m used to using Symfony’s EventDispatcher class to add event listeners and dispatch events, but I’m having trouble finding something analogous in Java because much of what I can find is about dealing with UI events, and I want to listen for and fire events on the server.

I’d also like the actual event handling to happen asynchronously on a separate thread or something, so that an API call to handle adding a payment can do what’s necessary, fire an event, and return immediately, even if the event triggers some more time-consuming stuff like sending emails or contacting a partner to inform them of the new balance.

Is it better to just write my own event interfaces, ExecutorService/Runnable, and Observer or Publish/Subscribe patterns? Or are there existing libraries (or built-in features I’m not aware of) that can handle some of this for me?  
Thanks!
