Spring application listeners instead of threads
Spring Provides e Application Listeners to handle Application Events. I want to get rid of my Thread classes and use these 开发者_开发技巧listeners for event handling .Any hint to start?Can I do this?
Please consider that ApplicationListener notification is synchronous by default thus it's not direct replacement for any asynchronous solution based on threads that you might have. On the other hand it's possible to change default strategy of events delivery to make it asynchronous (but it still will require some coding). I would start straight from Spring documentation :)
You can extend ApplicationEvent for your custom event and implement ApplicationListener to handle it. These events are synchronous (blocking).
Or you can make use of AsyncTaskExecutor to turn them asynchronous.
You can find an example of the later in this answer.
精彩评论