简体   繁体   English

@Controller类需要是原型还是单例?

[英]@Controller classes need to be prototype or singleton?

I am using Spring MVC for a web app 我正在将Spring MVC用于Web应用程序

The response time is around 250ms and speed is everything with this app 该应用程序的响应时间约为250毫秒,而速度就是一切

So when it comes to defining the Controller classes I have made then prototype so many can be running at the same time. 因此,当涉及到定义我制作的Controller类时,便可以同时运行许多原型。 The app is stateless 该应用程序是无状态的

I hope to do some performance test soon but wanted to get opinions if making controller classes prototype would improve performance over singleton? 我希望很快进行一些性能测试,但想征询意见,是否使控制器类原型可以提高单例性能?

Unless your controller methods are not thread-safe it is better to use "singleton" option. 除非您的控制器方法不是线程安全的,否则最好使用“ singleton”选项。 As otherwise any a new instance is created for each request. 否则,将为每个请求创建任何新实例。

But actually I don't think you will notice a great difference in performance for a single request as an overhead of new instance creation should be very small. 但是实际上我认为您不会注意到单个请求的性能有很大的不同,因为创建新实例的开销应该很小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM