英文:
Java Grizzly HTTP Server working to capacity 100% CPU usage on some threads
问题
我正在使用Grizzly Http Server在我的Web服务器上提供REST API。经过一段时间,服务器的负载越来越高,即使没有更多的用户在线。
在htop
中,我可以看到有一些Grizzly Http线程(在图片中是一个),它们正在使用一个内核的100%。这是怎么可能的?有什么想法吗?
代码:
/* IMPORTS */
public class WebAppServer {
private static WebAppServer instance;
public static WebAppServer getInstance() {
if (instance == null) instance = new WebAppServer();
return instance;
}
public void start() throws IOException, URISyntaxException {
String baseUrl = MavenPropertyDao.getInstance().getProperty(MavenPropertyDao.REST_SERVER_URL);
ResourceConfig rc = new MyConfig();
rc.register(new CORSFilter());
rc.registerClasses(/* REST CLASSES */);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(new URI(baseUrl), rc);
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
server.start();
}
public class MyConfig extends ResourceConfig {
public MyConfig() {
register(new HttpExceptionHandler());
register(MultiPartFeature.class);
register(GsonProvider.class);
property(ServerProperties.MONITORING_STATISTICS_ENABLED, true);
}
}
}
一天后的htop截图:
英文:
Im using the Grizzly Http Server on my webserver to serve a REST API. After some time the server is working more and more to full capacity even there are no more users online.
In htop
i can see that there are some grizzly http threads (at this time in the picture one) which are using 100% of one kernal. How is that possible? Any ideas?
Code:
/* IMPORTS */
public class WebAppServer {
private static WebAppServer instance;
public static WebAppServer getInstance() {
if (instance == null) instance = new WebAppServer();
return instance;
}
public void start() throws IOException, URISyntaxException {
String baseUrl = MavenPropertyDao.getInstance().getProperty(MavenPropertyDao.REST_SERVER_URL);
ResourceConfig rc = new MyConfig();
rc.register(new CORSFilter());
rc.registerClasses(/* REST CLASSES */);
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(new URI(baseUrl), rc);
Runtime.getRuntime().addShutdownHook(new Thread(server::stop));
server.start();
}
public class MyConfig extends ResourceConfig {
public MyConfig() {
register(new HttpExceptionHandler());
register(MultiPartFeature.class);
register(GsonProvider.class);
property(ServerProperties.MONITORING_STATISTICS_ENABLED, true);
}
}
}
专注分享java语言的经验与见解,让所有开发者获益!
评论