简体   繁体   English

弹簧座控制器,带和不带可调用

[英]spring rest controller with and without callable

First I wrote simple spring REST controller 首先,我编写了简单的spring REST控制器

 @RequestMapping(value = "/id", method = RequestMethod.GET)
    public String getDetails(@PathVariable("id") String id) {
       // wrote logic for JSON response....
}

Second we need to improve the performance so I wrote controller using Callable like this 其次,我们需要提高性能,所以我像这样使用Callable编写了控制器

@RequestMapping(value = "/id", method = RequestMethod.GET)
        public String getDetails(@PathVariable("id") String id) {
          return new Callable<String>(){
          @Override
          public String call() throws Exception {
           // ...
          return "someJSONString";
         }
       }
    }

Now the problem is when I compare the performance using JMETER for both above methods I dont see any major differences. 现在的问题是,当我使用JMETER比较上述两种方法的性能时,我看不到任何重大差异。

So do I miss anything while writing Callable controller? 那么编写Callable控制器时我会错过任何东西吗?

you can not improve single request performance with using Callable interface, it helps to take more request in some cases. 使用Callable接口无法提高单个请求的性能,在某些情况下,它有助于处理更多请求。 If your response type would be void, you can use runnable instead of callable, so with using runnable you can improve single request response time. 如果您的响应类型为空,则可以使用runnable而不是callable,因此使用runnable可以缩短单个请求的响应时间。 For example, if your service is suitable for fork/join framework try it. 例如,如果您的服务适合于fork / join框架,请尝试。

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

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