Ali*_*sam 6 java spring tomcat spring-mvc spring-boot
Callable通过在Spring Boot应用程序上运行的ajax 调用方法时,嵌入式tomcat异步处理请求并完全正常:
2017-07-02 09:12:24.283 INFO 3582 --- [nio-8090-exec-3] c.r.web.controllers.MainController : Ali was stored in redis
2017-07-02 09:12:25.671 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali is searching for a chat
2017-07-02 09:12:25.820 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali last activity date was updated in redis
2017-07-02 09:12:26.053 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali retrieving random conv null
2017-07-02 09:12:26.054 INFO 3582 --- [ngAsyncThread-1] c.r.web.controllers.MainController : Ali created my own conversation
2017-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 redis
2017-07-02 09:12:29.984 INFO 3582 --- [ngAsyncThread-2] c.r.web.controllers.MainController : Zeina is searching for a chat
2017-07-02 09:12:30.135 INFO 3582 --- [ngAsyncThread-2] c.r.web.controllers.MainController : Zeina last activity date was updated in redis
2017-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
Run Code Online (Sandbox Code Playgroud)
但是,当我在外部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 conversatio
2017-07-02 06:48:04.682 INFO 3324 --- [SpringAsyncThread-5] c.r.web.controllers.MainController : AJ is searching for a chat
2017-07-02 06:48:04.695 INFO 3324 --- [SpringAsyncThread-5] c.r.web.controllers.MainController : AJ last activity date was updated in redis
2017-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], person2=null, 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 chat
2017-07-02 06:48:50.845 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ last activity date was updated in redis
2017-07-02 06:48:50.860 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ retrieving random conv null
2017-07-02 06:48:50.860 INFO 3324 --- [SpringAsyncThread-6] c.r.web.controllers.MainController : AJ created my own conversation
2017-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...
Run Code Online (Sandbox Code Playgroud)
在上面的日志中,来自Zanzoun和的呼叫同时AJ被发送,但是AJ处理直到Zanzoun结束才开始.
下面我列出我的配置:
@Configuration
@EnableAsync
public 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
@EnableAsync
public 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);
}
}
Run Code Online (Sandbox Code Playgroud)
更新1
我应用了@divine评论中提供的答案,但问题没有解决:
<Connector port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
minProcessors="3"
maxProcessors="8"
maxThreads="20"
connectionTimeout="150000"
asyncTimeout="150000" />
Run Code Online (Sandbox Code Playgroud)
更新2
我已经使用外部Tomcat在我的Linux机器上进行本地测试8.0.21,它运行良好.但是,我在Windows中安装了相同版本的Tomcat(它实际上是一个AWS实例),问题仍然存在,所以这是一个操作系统/版本问题?
更新3
这是pom所要求的文件:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.randomni</groupId>
<artifactId>web</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Define that this project is a child of the spring-boot-starter-parent
project which contains all default maven configuration, this project inherits
all these configurations -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<!-- Main Web Dependency, contains MVC and Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mobile</artifactId>
</dependency>
<!-- Spring MVC with Thymeleaf views -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- WebJars -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>webjars-locator</artifactId>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>sockjs-client</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>stomp-websocket</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>normalize.css</artifactId>
<version>5.0.0</version>
</dependency>
<!-- For Deployment -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
<!-- Default Thymeleaf of Spring Boot is version 2, so we had to add these -->
<thymeleaf.version>3.0.6.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.2</thymeleaf-layout-dialect.version>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
shp*_*chu -1
您是否尝试过检查实际池大小,例如通过 JMX: https: //wiki.apache.org/tomcat/FAQ/Monitoring#Thread_Usage?
另外,您可以尝试安装 APR Native 库来验证问题不在于传入流量的自动选择协议:https ://tomcat.apache.org/tomcat-8.0-doc/apr.html
Windows EC2 实例的配置也可能会影响观察到的行为,您能否将其也添加到问题中?
| 归档时间: |
|
| 查看次数: |
585 次 |
| 最近记录: |