一个让人超级坑爹的tomcat机制

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Mikeoperfect/article/details/79901169
前言
前些日子赶上了阿里云的豪车,勒紧裤腰买了两年的阿里云主机,买完后很是兴奋,赶紧上线部署一个个人博客玩玩,有刚需的可以走链接:(有优惠)* https://promotion.aliyun.com/ntms/act/group/team.html?group=xubxmgq0Vv

本次采用的博客系统是GitHub上名噪一时的[]B3log开源博客,后端采用的是Java框架,对新人十分友好,上传war包到tomcat目录下之后,如果tomcat运行时会直接解压,然后你就可以开始访问了。

坑爹的遭遇

当我部署完我的开源博客后,查看了下我的主机的硬盘大小,只有40G的SSD,心里想着,这么小,能省一点空间是一点空间,于是在tomcat还在运行的情况下,ssh远程删除了war包(毕竟有几十M),然后若无其事的返回了 我的博客网站,看到网站加载速度极其缓慢,一开始还抱怨着阿里云网络波动也太大了吧,访问个博客等半天,但是连续刷新几次之后,通过ping排查了网络问题之后,才意识到出大问题了,然后再返回tomcat目录下,才惊奇的发现我的个人博客目录呢!!!,翻遍天了都没找到,桑心的倒在键盘上。 怎么会这样呢,我只删除了war包 而已,怎么会把解压后的war包也给收拾了呢,一开始还以为是个**天大的BUG** 以为是SSH远程命令解析时出现了什么故障,开启wireshark抓包后也没发现什么线索,直到我看到这样的解释:。。。 PS:感谢:https://blog.csdn.net/u012416792/article/details/77975930

tomcat 的war包机制

在tomcat中webapps目录上传war包后.



  • war不能在tomcat运行时删除,否则会删除自动解压的工程。 你可以停止tomcat后删除war。
  • 当你重新部署的时候,如果有与war文件相同的文件夹,就不会重新部署。
  1. 因为tomcat在运行期, 会實時监控webapps目錄下的war文件,如果有新增的war,就去解压它; 有删除war,就连同项目一起删除 .
  2. 所以,如果您要删除,可以先关闭tomcat再删除,这样不会有影响的


  • Tomcat/webapps下的WAR包和同名已解压项目,如何加载??

  1. 首先你要明白什么时候war包才会解压
  2. tomcat启动时候会去查看webapps目錄下的所有war包,同时查看是否有该war包对应的已解压的同名文件夹
  3. 如果已经存在就不会再解压也不會覆蓋該工程下已經被修改過的文件.
  4. 只有当你删除war包对应的同名文件夹(即 你的工程 )后,启动tomcat时才会再進行解压war文件動作



小结

不得不说,懂得背后的原理才能够真正的避免错误,否则瞎蒙真的不是特别好玩,所以说,知识确实是需要好好的积淀的,慢慢来吧。。
ps:有兴趣访问个人博客的伙伴欢迎友链哇:—MikeoPerfect的个人日志

展开阅读全文

一个让人头痛的问题

10-10

在项目中我使用Spring JDNI进行数据连接.开始在服务器上没什么问题.可是有时会报错误:错误日志如下rnThe last packet successfully received from the server was56275 milliseconds ago.The last packet sent successfully to the server was 56275 milliseconds ago, which 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.rn2011-10-10 09:48:53,269 - [ERROR] [AbstractFlushingEventListener] - Could not synchronize database state with sessionrnorg.hibernate.exception.JDBCConnectionException: Could not execute JDBC batch updatern at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:72)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)rn at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)rn at org.hibernate.event.def.AbstractFlushingEventListener.performExecutionsrnCaused by: java.sql.BatchUpdateException: The last packet successfully received from the server was56275 milliseconds ago.The last packet sent successfully to the server was 56275 milliseconds ago, which 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.rn at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)rn at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)rn at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)rn at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)rn at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)rn at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)rn ... 36 morern2011-10-10 09:48:53,273 - [ERROR] [JDBCExceptionReporter] - Already closed.rn2011-10-10 09:48:53,274 - [ERROR] [JDBCExceptionReporter] - Already closed.rn2011-10-10 09:48:53,274 - [ERROR] [SessionFactoryUtils] - Could not close Hibernate Sessionrnorg.hibernate.exception.GenericJDBCException: Cannot close connectionrn at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)rn at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)rn at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)rn at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:347)rn at org.hibernate.jdbc.ConnectionManager.cleanup(ConnectionManager.java:277)rn at org.hibernate.jdbc.ConnectionManager.close(ConnectionManager.java:218)rn at org.hibernate.impl.SessionImpl.close(SessionImpl.java:317)rn at com.fxun.commons.plant.bl.impl.UserOperateManagerImpl.generateGoodsID(UserOperateManagerImpl.java:93)rn at com.fxun.commons.plant.action.UserManagerAction.sendShop(UserManagerAction.java:686)rn at com.fxun.commons.plant.action.UserManagerAction.execute(UserManagerAction.java:64)rn at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)rn at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)rn at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)rn at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rn at com.easou.framework.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:88)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)rnCaused by: java.sql.SQLException: Already closed.rn at org.apache.tomcat.dbcp.dbcp.PoolableConnection.close(PoolableConnection.java:114)rn at org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.close(PoolingDataSource.java:191)rn at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.closeConnection(LocalDataSourceConnectionProvider.java:94)rn at org.hibernate.jdbc.ConnectionManager.closeConnection(ConnectionManager.java:343)rn ... 36 morern2011-10-10 09:48:53,275 - [INFO] [UserOperateManagerImpl] - =====ID浜х敓瑙勫垯 ===============缁撴潫===========rn2011-10-10 09:48:53,276 - [ERROR] [UserManagerAction] - error.sendShoprnorg.springframework.jdbc.UncategorizedSQLException: Hibernate operation: Could not execute JDBC batch update; uncategorized SQLException for SQL [update T_GOOD_SEQUENCE set SEQUENCE=? where CATEGORY_ID=? and TYPE_ID=?]; SQL state [08S01]; error code [0]; The last packet successfully received from the server was56275 milliseconds ago.The last packet sent successfully to the server was 56275 milliseconds ago, which 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.; nested exception is java.sql.BatchUpdateException: The last packet successfully received from the server was56275 milliseconds ago.The last packet sent successfully to the server was 56275 milliseconds ago, which 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.rn at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.translate(SQLStateSQLExceptionTranslator.java:96)rn at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.translate(SQLErrorCodeSQLExceptionTranslator.java:257)rn at org.springframework.orm.hibernate3.HibernateAccessor.convertJdbcAccessExceptionrn(Http11BaseProtocol.java:665)rn at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)rn at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)rn at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)rn at java.lang.Thread.run(Thread.java:595)rnCaused by: java.sql.BatchUpdateException: The last packet successfully received from the server was56275 milliseconds ago.The last packet sent successfully to the server was 56275 milliseconds ago, which 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.rn at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1693)rn at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1108)rn at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)rn at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)rn希望高手帮忙解释下 论坛

一个让人郁闷的错误

08-14

用Eclipse + MyEclipse + Weblogic8.1 + Oracle9i下用编写的web应用运行正常(在weblogic中配置的数据库连接池)。rnrn而在Dreamware下写jsp页面,在dos控制台下编译java文件,服务器仍用weblogic,数据库仍用Oracle9i,但运行时提示catch没有对应的try,但我确实都对应了try了。rnrn下面是我的OPENDB.jsp文件内容。rn<%@ page contentType="text/html;charset=gb2312"%> rn<%@ page import="java.sql.*"%> rnrn rn rnrn<%rn String sql="select * from t_user2";rn bean.setSqlCommend(sql);//设置sql语句rn tryrn ResultSet rs = bean.execSQL();//执行sql语句。除了查询语句select,其他的不用返回给rs.rn if(rs.next())rn System.out.println(rs.getString("username"));//若查出数据,加入对每一行数据的处理代码。rn rn bean.closeAll();//最后一定别忘了关闭,切记!rn catch(Exception e)rn e.printStackTrace();rn rn%> rnrn rnrnrn以下是我的MyDBOper.java文件内容rnpackage database;rnrnimport java.sql.*;rnimport javax.naming.Context;rnimport javax.naming.InitialContext;rnrnpublic class MyDBOper rn Connection myConn = null;//连接对象rn Statement stmt = null;rn String sqlCommend = "";rn rn public MyDBOper()rn tryrn Context ctx = new InitialContext();rn javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("MyOAPooledDB");rn myConn = ds.getConnection();rn catch(Exception e)rn e.printStackTrace();rn rn rn public void setSqlCommend(String sqlCommend) rn this.sqlCommend = sqlCommend;rn rn public void execSQL()rn if(sqlCommend!=null && !sqlCommend.equals(""))rn tryrn stmt = myConn.createStatement();rn stmt.execute(sqlCommend);rn catch(Exception e)rn e.printStackTrace();rn rn rn rn public void test()rn tryrn Statement stmt = myConn.createStatement();rn ResultSet rs = stmt.executeQuery("select * from test");rn while(rs.next())rn System.out.println(rs.getString("t_name")+" "+rs.getString("t_pass"));rn rn catch(Exception e)rn e.printStackTrace();rn rn rn public void closeAll()rn tryrn stmt.close();rn myConn.close();rn catch(Exception e)rn e.printStackTrace();rn rn rnrnrnrn以下是错误提示:rnCompilation of 'D:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java' failed:rn--------------------------------------------------------------------------------rn D:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:150: 'catch' without 'try'rn(No more information available, probably caused by another error)rnrnD:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:161: '' expectedrn(No more information available, probably caused by another error)rnrnD:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:122: 'try' without 'catch' or 'finally'rn(No more information available, probably caused by another error)rnrnrn--------------------------------------------------------------------------------rnFull compiler error(s):rnD:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:150: 'catch' without 'try'rn catch (Throwable __ee) rn ^rnD:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:161: '' expectedrn^rnD:\bea\user_projects\domains\dev\.\myserver\.wlnotdelete\extract\myserver__appsdir_change_dir_change\jsp_servlet\__opendb.java:122: 'try' without 'catch' or 'finally'rn try // error page try blockrn ^rn3 errorsrnrn 论坛

tomcat 连接池的一个超级bug!!!

07-03

下面是一个servlet 里的 doPOST 方法的代码rnrn我tomcat 连接池 maxActive =8 结果执行8次后 就无法得到 Connection了(为null)而且getConnection变得很慢(等于maxWait设置的时间)rnrn如果我 maxActive 设置为4 那么就四次以后不行 我每次都很小心的关闭 为什么关闭的Connection无法再利用??rn==================================================rn protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException rn String keyword = request.getParameter("keyword");rn boolean hasData = false;rn rn Context ctx=null;rn Connection conn=null;rn Statement stmt=null;rn ResultSet rs=null;rn rn tryrn ctx=new InitialContext();rn DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sample");rn if(ds!=null)rn conn=ds.getConnection();//问题所在!rn rn if(conn != null)rn HttpSession session = request.getSession();rn session.setAttribute("sou4sou_keyword",keyword);rnrn stmt = conn.createStatement() ;rn rs = stmt.executeQuery("select top 1 id from searchdata where keyword like '%"+keyword+"%'");rn System.out.println("select top 1 id from searchdata where keyword like '%"+keyword+"%'");rn if(rs.next())rn hasData = true;rn rn rn rs.close();rn rs = null;rn stmt.close();rn stmt = null;rn conn.close(); // Return to connection poolrn conn = null; rn catch(Exception e)rn e.printStackTrace();rn finallyrn tryrn if (rs != null) rn try rs.close(); catch (SQLException e) ; rn rs = null;rn rn if (stmt != null) rn try stmt.close(); catch (SQLException e) ; rn stmt = null;rn rn if (conn != null) rn try conn.close(); catch (SQLException e) ; rn conn = null;rn rnrn catch(Exception e)rn rn rn rn rn ServletContext sc = getServletContext();rn RequestDispatcher rd = null; rn if(hasData)rn rd = sc.getRequestDispatcher("/list.jsp");rn rd.forward(request,response);rn elsern rd = sc.getRequestDispatcher("/souproxy.jsp");rn rd.forward(request,response);rn rn rnrnrn================================================== 论坛

jmail让人兴奋让人忧!

03-23

不能发送符件,(异常)rnrnjavax.mail.MessagingException: IOException while sending message;rn nested exception is:rn java.io.FileNotFoundException: dor.xls (系统找不到指定的文件。)rnrnrnrnrnrn各位帮喵一下,:代码(部分)rnif(filename!=null)rn // 信件内容:rn MimeBodyPart mbp1=new MimeBodyPart();//新建一个存放信件内容body对象。rn mbp1.setContent(context, type+";charset=gbk");//对于邮件的普通信息的类型处理以及编码处理。rn/* 从struts的actionForm中获得FormFile rn 1.String fileName=String.valueOf(formfile); rn 2.String fileName = new String(formfile.getFileName().getBytes("UTF-8"),"UTF-8"); rn 将FormFile转型为 String*/rn rn // 附件的处理:rn String fname=String.valueOf(filename);rn //System.out.println(filename);rn File file=new File(fname);//存留备份rn MimeBodyPart mbp2=new MimeBodyPart();rn rn FileDataSource fds=new FileDataSource(file);rn mbp2.setDataHandler(new DataHandler(fds));rn rn try rn mbp2.setFileName(MimeUtility.encodeText(fds.getName(),"gbk","B"));rn System.out.println(mbp2.getFileName());rn catch (UnsupportedEncodingException e) rn // TODO Auto-generated catch blockrn e.printStackTrace();rn rn Multipart mp=new MimeMultipart();rn mp.addBodyPart(mbp1);//将body里的内容往mp存放,最后set值 。rn mp.addBodyPart(mbp2);rn msg.setContent(mp);rn elsern msg.setContent(context, type+";charset=gbk");rn System.out.println(context);rn //信封的书写格式rn 论坛

没有更多推荐了,返回首页