解决异常:“The last packet sent successfully to the server was 0 milliseconds ago. ”的办法
出现异常”The last packet sent successfully to the server was 0 milliseconds ago.“的大部分原因是由于数据库回收了连接,而系统的缓冲池不知道,继续使用被回收的连接所致的。
以mysql为例:
第一种解决办法,就是将mysql回收空闲连接的时间变长,mysql默认回收时间是8小时,可以在mysql目录下的my.ini中增加下面配置,将时间改为1天。
单位是秒,最大好像是24天:
[mysqld]
wait_timeout=86400
第二种解决办法,可以通过配置,让缓冲池去测试连接是否被回收,如果被回收,则不继续使用,以dbcp为例:
#SQL查询,用来验证从连接池取出的连接
dbcp.validationQuery=SELECT 1
#指明连接是否被空闲连接回收器(如果有)进行检验,如果检测失败,则连接将被从池中去除
dbcp.testWhileIdle=true
#在空闲连接回收器线程运行期间休眠的时间值,以毫秒为单位,一般比minEvictableIdleTimeMillis小
dbcp.timeBetweenEvictionRunsMillis=300000
#在每次空闲连接回收器线程(如果有)运行时检查的连接数量,最好和maxActive一致
dbcp.numTestsPerEvictionRun=50
#连接池中连接,在时间段内一直空闲,被逐出连接池的时间(1000*60*60),以毫秒为单位
dbcp.minEvictableIdleTimeMillis=3600000
*********************************
如何解决:待定;
分析问题:
第一:因为自己的appkey和appSecret是正确的,并且这个程序在家里面的电脑是没有问题的,但是在公司执行的时候就报错误。
第二:是不是其他公司代理导致问题存在呢?还是?下面达内老师为大家分享具体内容。
淘宝客开发过程遇到问题:
//开始调用淘宝API接口
TaobaoClient client = new DefaultTaobaoClient(url, appkey, appSecret);
TaobaokeItemsGetRequest req=new TaobaokeItemsGetRequest();
req.setFields("num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume");
//返回数据
TaobaokeItemsGetResponse response = client.execute(req);
List<TaobaokeItem> list = response.getTaobaokeItems();
System.out.println(list.size());
Pageinfo newpage =new Pageinfo(defaultCurpage, pageno, pagesize, list); //生成Page
//生成json数据
String listJson = JSON.toJSONString(newpage, true);
System.out.println(listJson);
错误代码如下:
[java]
2012-12-12 9:26:51 com.taobao.api.internal.util.TaobaoLogger _logCommError
严重: 2012-12-12
09:26:51^_^taobao.taobaoke.items.get^_^1021298225^_^10.240.70.132^_^Windows
XP^_^top-sdk-java-20121129^_^http://gw.api.tbsandbox.com/router/rest?sign=AC99D0A45E6D90ECF5D3F62E05F2EA9E×tamp=2012-12-12+09%3A26%3A49&v=2.0&app_key=1021298225&method=taobao.taobaoke.items.get&sign_method=hmac&partner_id=top-sdk-java-20121129&format=json^_^^_^Connection
refused: connect
com.taobao.api.ApiException: java.net.ConnectException: Connection refused: connect
at com.taobao.api.DefaultTaobaoClient.doPost(DefaultTaobaoClient.java:200)
at com.taobao.api.DefaultTaobaoClient._execute(DefaultTaobaoClient.java:105)
at com.taobao.api.DefaultTaobaoClient.execute(DefaultTaobaoClient.java:83)
at com.taobao.api.DefaultTaobaoClient.execute(DefaultTaobaoClient.java:71)
at com.taobao.www.fanjf.action.DisplayPayedAction.getTaobaokeItemsListInit1(DisplayPayedAction.java:130)
at com.taobao.www.fanjf.action.DisplayPayedAction.execute(DisplayPayedAction.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:446)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:285)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at
org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:238)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:544)
at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
at com.taobao.api.internal.util.WebUtils.doPost(WebUtils.java:115)
at com.taobao.api.internal.util.WebUtils.doPost(WebUtils.java:88)
at com.taobao.api.internal.util.WebUtils.doPost(WebUtils.java:68)
at com.taobao.api.DefaultTaobaoClient.doPost(DefaultTaobaoClient.java:197)
… 74 more
以上就是今天达内IT培训老师为大家分享的有关Connection refused: connect错误的内容,相信能够帮助到大家。
************************************
今天在使用JDBC操作mysql时遇到下面的异常信息:
引用
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
at com.tomymap.galaxy.virgo.util.DbService.getConnection(DbService.java:66)
at com.tomymap.galaxy.virgo.util.DbService.getConnection(DbService.java:46)
at com.tomymap.galaxy.virgo.dao.PNNDao.getConnection(PNNDao.java:51)
at com.tomymap.galaxy.virgo.dao.DaoBase.executeUpdate(DaoBase.java:69)
at com.tomymap.galaxy.virgo.dao.PNNDao.updatePNNRelation(PNNDao.java:161)
at com.tomymap.galaxy.virgo.pnn.PyramidNeuralNetwork.buildPNNRelations(PyramidNeuralNetwork.java:400)
at com.tomymap.galaxy.virgo.pnn.PyramidNeuralNetwork.incrementalGenPNN(PyramidNeuralNetwork.java:144)
at com.tomymap.galaxy.virgo.pnn.PyramidNeuralNetwork.main(PyramidNeuralNetwork.java:410)
着实让人崩溃的信息,花费了一天的时间来解决。
不罗嗦,直接描述解决办法
1 配置:
2 ubuntu10.10
3 5.1.49-1ubuntu8.1
4 mysql-connector-java-5.1.18.jar
交互:
300k records
300k * 10 = 3M次访问mysql
处理时间0.5h以内
解决方法:
(1)使用JDBC URL中使用autoReconnect属性,url添加
&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
(2) 修改MySQL的参数. /etc/my.cnf 添加
[mysqld]
wait_timeout=31536000
interactive_timeout=31536000
(3)重启mysql
service mysql restart
原因分析:
(1)大量数据访问情况下,mysql connection连接有可能失效
(2)长时间不妨问,connection会失效
http://dev.mysql.com/doc/refman/5.1/zh/database-administration.html#dynamic-system-variables
http://www.blogjava.net/heweiya/archive/2006/01/18/28483.html
解决异常:“The last packet sent successfully to the server was 0 milliseconds ago. ”的办法的更多相关文章
- The last packet sent successfully to the server was 0 milliseconds ago
出现异常”The last packet sent successfully to the server was 0 milliseconds ago.“的大部分原因是由于数据库回收了连接,而系统的缓 ...
- The last packet sent successfully to the server was 0 milliseconds ago.[nutch---mysql ]
今天在使用JDBC操作mysql时遇到下面的异常信息: 引用 The last packet sent successfully to the server was 0 milliseconds ag ...
- The last packet successfully received from the server was 20,519 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
本地升级了下MySQL的版本,从5.6升为5.7,数据文件直接拷贝的,项目查询数据库报错: Could not retrieve transation read-only status server ...
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
今天项目中报了如下错误 The last packet sent successfully to the server was 0 milliseconds ago. The driver has n ...
- Communications link failure;;The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure::The ...
- docker 踩坑日记The last packet sent successfully to the server was 0 milliseconds ago.
The last packet sent successfully to the server was 0 milliseconds ago. 今日遇到了这个坑,看似平白无奇. 首先,我定位到是数据库 ...
- 【异常】The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
1 详细异常信息 The last packet sent successfully to the server was milliseconds ago. The driver has not re ...
- The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server. (关于jdbc)
The last packet sent successfully to the server was milliseconds ago. The driver has not received an ...
- 【错误】:Could not open JDBC Connection for transaction; nested exception is: Communications link failure;The last packet sent successfully to the server was 1 milliseconds ago
# #错误日志 2016-11-10 16:19:20,834 ERROR [org.quartz.core.JobRunShell] - Job DEFAULT.jobtask threw an u ...
随机推荐
- javascriptRemke之深入迭代
javascriptRemke之深入迭代 前言:"迭代"意为按照顺序反复多次执行一段程序,ECMAscript6中新增了两个高级特性:迭代器与生成器,使用这两个特性能更高效地实现迭 ...
- 七牛云的 python sdk 是如何 批量删除资源的
今天做项目的时候用到七牛云,关于对资源的操作是在后端做的,用的SDK,但是,在网上没找到详细的解析,官方文档也没有太详细的解说,所以无奈只好看下源码 这里做一下简单的记录 from qiniu imp ...
- 洛谷3809 SA模板 后缀数组学习笔记(复习)
其实SA这个东西很久之前就听过qwq 但是基本已经忘的差不多了 嘤嘤嘤 QWQ感觉自己不是很理解啊 所以写不出来那种博客 QWQ只能安利一些别人的博客了 小老板 真的是讲的非常好 不要在意名字 orz ...
- 用C++实现的数独解题程序 SudokuSolver 2.3 及实例分析
SudokuSolver 2.3 程序实现 用C++实现的数独解题程序 SudokuSolver 2.2 及实例分析 里新发现了一处可以改进 grp 算法的地方,本次版本实现了对应的改进 grp 算法 ...
- NX开发库版本问题
有做NX二次开发的朋友经常问我这样的问题:我在NX8.0上开发的程序,可以在NX9.0上运行吗? 由于NX的开发库随着版本的更新也会不断更新,会增加新的方法,同时有些也会过时或者消失. 如下图:NX8 ...
- 自动化运维利器Ansible要点汇总
由于大部分互联网公司服务器环境复杂,线上线下环境.测试正式环境.分区环境.客户项目环境等造成每个应用都要重新部署,而且服务器数量少则几十台,多则千台,若手工一台台部署效率低下,且容易出错,不利后期运维 ...
- MAC 安装 apache ab 压力测试工具以及遇到的坑
ab 是apache对 http服务器进行压力测试的工具,它可以测试出服务器每秒可以处理多少请求.本文记录mac版本安装 ab 的步骤以及遇到的坑. 下载 进入 apache ab官网 下载页面. 安 ...
- 【UE4 C++】Print、Delay、ConsoleCommand
基于UKismetSystemLibrary PrintString /** * Prints a string to the log, and optionally, to the screen * ...
- Netty学习笔记(2)ByteBuffer
1. 测试ByteBuffer 1.1 依赖 <dependencies> <dependency> <groupId>io.netty</groupId&g ...
- Coursera Deep Learning笔记 深度卷积网络
参考 1. Why look at case studies 介绍几个典型的CNN案例: LeNet-5 AlexNet VGG Residual Network(ResNet): 特点是可以构建很深 ...