开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜