通过在Spring Boot应用程序上运行的AJAX调用Callable方法时,嵌入式tomcat异步处理请求并完全正常:
2017-07-02 09:12:24.283 INFO 3582 --- [nio-8090-exec-3] c.r.web.controllers.MainController : Ali was stored in redis2017-07-02 09:12:25.671 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali is searching for a chat2017-07-02 09:12:25.820 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali last activity date was updated in redis2017-07-02 09:12:26.053 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali retrIEving random conv null2017-07-02 09:12:26.054 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali created my own conversation2017-07-02 09:12:26.211 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali searching...2017-07-02 09:12:27.927 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali searching...2017-07-02 09:12:29.128 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali searching...2017-07-02 09:12:29.305 INFO 3582 --- [nio-8090-exec-2] c.r.web.controllers.MainController : Zeina was stored in redis2017-07-02 09:12:29.984 INFO 3582 --- [ngAsyncThread-2] c.r.web.controllers.MainController : Zeina is searching for a chat2017-07-02 09:12:30.135 INFO 3582 --- [ngAsyncThread-2] c.r.web.controllers.MainController : Zeina last activity date was updated in redis2017-07-02 09:12:30.285 INFO 3582 --- [ngAsyncThread-2] c.r.web.controllers.MainController : Zeina retrIEving random conv Conversation [ID=bbb17857-9049-4,person1=Person [ID=9a243d57-2f0c-4,name=Ali,age=22,gender=M,ip=0:0:0:0:0:0:0:1,loginDate=Sun Jul 02 09:12:23 EEST 2017,lastActiveDate=Sun Jul 02 09:12:25 EEST 2017],person2=null,creationDate=Sun Jul 02 09:12:26 EEST 2017]2017-07-02 09:12:30.687 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali searching...2017-07-02 09:39:54.420 INFO 3582 --- [ngAsyncThread-3] c.r.web.controllers.MainController : Zeina is searching for a chat
但是,当我在外部tomcat服务器上部署应用程序时,一个调用挂起服务器,而下一个调用仅在第一次调用完成后处理.
2017-07-02 06:47:57.285 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:47:58.297 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:47:59.309 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:48:00.323 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:48:01.335 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:48:02.347 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:48:03.359 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun searching...2017-07-02 06:48:04.388 INFO 3324 --- [SpringAsyncThread-4] c.r.web.controllers.MainController : Zanzoun remove dead conversatio2017-07-02 06:48:04.682 INFO 3324 --- [SpringAsyncThread-5] c.r.web.controllers.MainController : AJ is searching for a chat2017-07-02 06:48:04.695 INFO 3324 --- [SpringAsyncThread-5] c.r.web.controllers.MainController : AJ last activity date was updated in redis2017-07-02 06:48:04.708 INFO 3324 --- [SpringAsyncThread-5] c.r.web.controllers.MainController : AJ retrIEving random conv Conversation [ID=f5fe39ac-91ce-4,person1=Person [ID=e25d18f3-9729-4,name=Zanzoun,age=12,gender=F,ip=91.197.46.40,loginDate=Sun Jul 02 06:47:32 UTC 2017,lastActiveDate=Sun Jul 02 06:47:48 UTC 2017],creationDate=Sun Jul 02 06:47:48 UTC 2017]2017-07-02 06:48:50.833 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ is searching for a chat2017-07-02 06:48:50.845 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ last activity date was updated in redis2017-07-02 06:48:50.860 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ retrIEving random conv null2017-07-02 06:48:50.860 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ created my own conversation2017-07-02 06:48:50.872 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ searching...2017-07-02 06:48:51.884 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ searching...2017-07-02 06:48:52.896 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ searching...2017-07-02 06:48:53.908 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ searching...2017-07-02 06:48:54.921 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ searching...
在上面的日志中,来自Zanzoun和AJ的电话同时被发送,但是在Zanzoun结束之前AJ处理没有开始.
下面我列出我的配置:
@Configuration@EnableAsyncpublic class MvcConfig extends WebMvcConfigurerAdapter { @OverrIDe public voID addVIEwControllers(VIEwControllerRegistry registry) { registry.addVIEwController("/").setVIEwname("main"); registry.addVIEwController("/login").setVIEwname("login"); registry.addVIEwController("/admin").setVIEwname("admin"); } @OverrIDe public voID configureAsyncSupport(AsyncSupportConfigurer configurer) { configurer.setTaskExecutor(asyncTaskExecutor()); } @Bean public AsyncTaskExecutor asyncTaskExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(10); executor.setMaxPoolSize(200); executor.setQueueCapacity(500); executor.setThreadnamePrefix("SpringAsyncThread-"); executor.initialize(); return executor; }}@SpringBootApplication@EnableScheduling@EnableAsyncpublic class App extends SpringBootServletinitializer { public static voID main(String[] args) { SpringApplication.run(App.class,args); } @OverrIDe protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(App.class); }}
更新1
我应用了@divine评论中提供的答案,但问题没有解决:
更新2
我已经使用外部Tomcat 8.0.21在我的linux机器上进行了本地测试,它运行良好.但是,我在windows中安装了相同版本的Tomcat(它实际上是一个AWS实例),问题仍然存在,所以这是一个 *** 作系统/版本问题?
更新3
这是所要求的pom文件:
最佳答案您是否尝试过检查实际池大小,例如,通过JMX:https://wiki.apache.org/tomcat/FAQ/Monitoring#Thread_Usage?此外,您是否可以尝试安装APR Native库来验证问题不是自动选择的传入流量协议:https://tomcat.apache.org/tomcat-8.0-doc/apr.html
windows EC2实例的配置也可能会影响观察到的行为,您是否也可以将其添加到问题中?
总结 以上是内存溢出为你收集整理的java – Spring Boot外部Tomcat不是异步的全部内容,希望文章能够帮你解决java – Spring Boot外部Tomcat不是异步的所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)