简体   繁体   English

API 服务每隔一个请求工作一次

[英]API service works every second request

I have problem with jax-rs REST service.我对 jax-rs REST 服务有问题。

Service does not operate properly.服务运行不正常。 Every second request service throw me exception:每隔一秒请求服务就会抛出异常:

HTTP Status 500 - could not execute query

type Exception report

message could not execute query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.hibernate.exception.JDBCConnectionException: could not execute query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.loader.Loader.doList(Loader.java:2147)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
    org.hibernate.loader.Loader.list(Loader.java:2023)
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62)
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37)
    com.fit.servis.Korisnik_servis.PronadjiPrijatelje(Korisnik_servis.java:174)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed by the driver.
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    java.lang.reflect.Constructor.newInstance(Unknown Source)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    com.mysql.jdbc.Util.getInstance(Util.java:384)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929)
    com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1204)
    com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1191)
    com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4276)
    com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4242)
    org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
    org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
    org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
    org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1560)
    org.hibernate.loader.Loader.doQuery(Loader.java:661)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    org.hibernate.loader.Loader.doList(Loader.java:2144)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
    org.hibernate.loader.Loader.list(Loader.java:2023)
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62)
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37)
    com.fit.servis.Korisnik_servis.PronadjiPrijatelje(Korisnik_servis.java:174)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 22.477.953 milliseconds ago.  The last packet sent successfully to the server was 22.478.000 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    java.lang.reflect.Constructor.newInstance(Unknown Source)
    com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1122)
    com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3317)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1941)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
    org.hibernate.loader.Loader.doQuery(Loader.java:662)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    org.hibernate.loader.Loader.doList(Loader.java:2144)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
    org.hibernate.loader.Loader.list(Loader.java:2023)
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62)
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37)
    com.fit.servis.Korisnik_servis.Login(Korisnik_servis.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.net.SocketException: Software caused connection abort: socket write error
    java.net.SocketOutputStream.socketWrite0(Native Method)
    java.net.SocketOutputStream.socketWrite(Unknown Source)
    java.net.SocketOutputStream.write(Unknown Source)
    java.io.BufferedOutputStream.flushBuffer(Unknown Source)
    java.io.BufferedOutputStream.flush(Unknown Source)
    com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3298)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1941)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2114)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2696)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2105)
    com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2264)
    org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    org.hibernate.loader.Loader.getResultSet(Loader.java:1668)
    org.hibernate.loader.Loader.doQuery(Loader.java:662)
    org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
    org.hibernate.loader.Loader.doList(Loader.java:2144)
    org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2028)
    org.hibernate.loader.Loader.list(Loader.java:2023)
    org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:95)
    org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
    org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
    com.fit.utilities.BaseDAO.getAll_fetchEager(BaseDAO.java:62)
    com.fit.utilities.BaseDAO.getAll(BaseDAO.java:37)
    com.fit.servis.Korisnik_servis.Login(Korisnik_servis.java:32)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
    com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1483)
    com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1414)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1363)
    com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1353)
    com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:414)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.32 logs.

Apache Tomcat/7.0.32

Service retrieve JSON..I think that the problem is due to the size byte string.服务检索 JSON..我认为问题是由于字节字符串的大小造成的。

Example of successful response:成功响应示例:

[{
    "id": 2,
    "name": "haris",
    "surname": null,
    "gender": null,
    "age": null,
    "birthdate": null,
    "password": "1234",
    "username": "haris",
    "isOnline": null,
    "picture": "YORp0a9HAkEbrPYu2RcNwB4ExIMdvoD5/3uBgoz1"
}]

The problem is in your mysql datasource configuration.问题出在您的 mysql 数据源配置中。 Try to add this two parameters to the datasource definition:尝试将这两个参数添加到数据源定义中:

 testOnBorrow="true" validationQuery="select 1"

I guess this is server side problem.我想这是服务器端的问题。 Its clearly visible your class BaseDAO executing a method getAll_fetchEager in this method you are making some criteria query which fails due to some reason.它清楚地可见您的类BaseDAO在此方法中执行方法getAll_fetchEager您正在执行一些由于某种原因而失败的条件查询。 I am sure if you correct your criteria query problem will resolve.我相信如果您更正您的标准查询问题将得到解决。 Try to find out connection properties are properly set and you are able to connect your database.尝试找出正确设置的连接属性,并且您能够连接您的数据库。

I think the answer is in the stack trace.我认为答案在堆栈跟踪中。

The last packet successfully received from the server was 22.477.953 milliseconds ago. 从服务器成功接收的最后一个数据包是 22.477.953 毫秒前。 The last packet sent successfully to the server was 22.478.000 milliseconds ago. 最后一个成功发送到服务器的数据包是 22.478.000 毫秒前。 is longer than the server configured value of 'wait_timeout'. 比服务器配置的“wait_timeout”值长。 You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 您应该考虑在应用程序中使用之前使连接有效性过期和/或测试连接有效性,增加客户端超时的服务器配置值,或使用连接器/J 连接属性“autoReconnect=true”来避免此问题。

The connection to your mysql isn't being kept open, and isn't set to auto reconnect.与您的mysql的连接未保持打开状态,也未设置为自动重新连接。

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

相关问题 绝对每秒使用Java发送15条记录作为api请求 - Sending 15 records as api request in every one second absolutely with Java 每隔一个使用 Apache HTTPClient 的请求就会失败 - Every second request using Apache HTTPClient fails android上的套接字,第二个请求消失 - socket on android, every second request disappears Are new instances of Service, Repository and Component created for every new request of spring mvc rest api or spring boot api to application server? - Are new instances of Service, Repository and Component created for every new request of spring mvc rest api or spring boot api to application server? 每隔10秒从后台服务显示一条自定义消息 - show a custom message every 10 second from background service 这是服务中每隔x秒重复一次方法的正确方法吗? - This is the correct way to repeat method every x second in service? 是否可以将ajax(xmlhttprequest)发送的每个请求作为Web服务请求调用? - Can every request send by ajax (xmlhttprequest) be called as web service request? 后台服务使 API 28 上的应用程序崩溃,但适用于 API 23 - Background service crashes application on API 28 but works on API 23 Android:如何每隔10秒通过服务发送http请求 - Android: How to send http request via service every 10 seconds Android:如何每隔5秒通过服务发送一次HTTP请求 - Android: How to send http request via service every 5 seconds
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM