2

I understand how ApplicationScoped and CDI javax.inject.Singleton work, and I understand the difference between these two scopes. My app has a lot of beans that don't need serialization, proxies, or decorations, so I am considering switching those from ApplicationScoped (which works) to javax.inject.Singleton to improve performance by avoiding proxies.

My question is: Should I in fact make such a change?

4

1 回答 1

0

当然,您可以对范围注释进行重构,但您需要处理调用那些单例托管 bean 的 bean 的序列化。请参阅http://docs.jboss.org/weld/reference/latest-2.2/en-US/html_single/#_the_singleton_pseudo_scope

我将首先调查我将从这一举措中获得多少性能提升,以及是否真的值得花时间进行投资。通常性能瓶颈来自数据库查询/索引性能、I/O、网络、线程锁、Java 代理开销之前的低效算法(等等),所以我会坚持使用标准的@ApplicationScoped。

见: http: //ordinaryjava.blogspot.com/2008/08/benchmarking-cost-of-dynamic-proxies.html https://spring.io/blog/2007/07/19/debunking-myths-proxies-impact -表现/

于 2019-02-03T20:47:18.063 回答