解决异常:“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 ...
随机推荐
- Spring源码之创建AOP代理之增强器的获取
前言 在上一篇博文中我们说到了通过自定义配置完成了对AnnotationAwareAspectJAutoProxyCreator类型的自动注册,那么这个类究竟做了什么工作从而完成AOP的操作呢?首先我 ...
- TWAIN-v2.4-说明文档翻译(2)技术概览
技术概览 Technical Overview TWAIN架构(TWAIN Architecture) 数据交互的实现在TWAIN中由三类软件元素共同工作完成:应用程序(the application ...
- 解决VSCODE"因为在此系统上禁止运行脚本"报错
在VSCODE中使用yarn,结果报错: 找了下原因,是因为PowerShell执行策略的问题. 解决方法: 以管理员身份运行vscode; 执行:get-ExecutionPolicy,显示R ...
- websocket方案调研及实践
目录 webscoket方案调研及实践 一.使用场景 二.方案调研 1.Ajax短轮询 2.long-polling长轮询 3.iframe长连接 4.XHR-streaming 5.Websocke ...
- Kubernetes-Service介绍(三)-Ingress(含最新版安装踩坑实践)
前言 本篇是Kubernetes第十篇,大家一定要把环境搭建起来,看是解决不了问题的,必须实战. Kubernetes系列文章: Kubernetes介绍 Kubernetes环境搭建 Kuberne ...
- C++ 类继承 笔记(初步)
本节内容源于对C++ primer第13章的学习,这本书把C++的原理将得明明白白.网上的博客往往讲得一头雾水.到头来还不如看原书本. 问题 首先给出一题: #include<stdio.h&g ...
- OO电梯作业总结
(一)第五次作业 一.设计思路 生产消费者模型,输入接口是producer,调度器是tray,电梯是customer.由于只有一架电梯,所以生产消费模型满足以下条件: 一个生产者,一个消费者 托盘不为 ...
- (数据科学学习手札129)geopandas 0.10版本重要新特性一览
本文示例代码及文件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 就在前不久,我们非常熟悉的Python地理 ...
- java中生成和验证jwt
在这篇文章中主要记录一下在Java中如何使用 java 代码生成jwt token,主要是使用jjwt来生成和验证jwt,关于什么是JWT,以及JWT可以干什么不做详解. jwt的格式: base64 ...
- 简明教程 | Docker篇 · 其二:Dockerfile的编写
Dockerfile是什么 一个包含用于组合 image 的命令的文本文件,docker 通过 dockerfile 和构建环境的上下文来构建 image . 编写Dockerfile FROM 首先 ...