`
voff12
  • 浏览: 96378 次
  • 来自: 北京
社区版块
存档分类
最新评论

用hibernate竟然会把tomcat“干掉”,真是奇怪

阅读更多
问题所在:
用struts1.0+hibernate3.1(mysql数据库)第一次写了一个简单的小网站。解决了很多很多问题后,最后卡在tomcat“崩溃"上。
tomcat启动后,几小时内可以正常运行。但几个小时后,点击连接,或访问主页时,进不去。也不报错,处理36%状况(1%变至38%)不动。。

这种情况下关闭tomcat,重启tomcat有问题。重启时显示tomcat已启动。


运行环境配置
运行环境配置
1)apache2.2.4+tomcat5.0.28+redhat9.0+jkd1.5.0_09
2)配置文件如下:
LoadModule jk_module modules/mod_jk.so

<IfModule mod_jk.c>
JkWorkersFile "/usr/local/apache/conf/workers.properties"
JkLogFile "logs/mod_jk.log"
JkLogLevel warn

#JkMount /jsp-examples worker1
#JkMount /jsp-examples/* worker1
# Map in the Ozibug webapp
JkMount /yahoo/* worker1

</IfModule>

<IfModule mod_limitipconn.c>
 <Location /yahoo>
    MaxConnPerIP 1000
 </Location>
</IfModule>


apache的conf下workers.properties配置
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300





原因分析与解决尝试:
1)个人认为可以是hibernate连接池有问题.google一下,采用了三个方案(默认,c3p0,proxool)但发现全部有“缺点”(可能还未懂配置的含义)。用proxool出现显示不稳定的情况。用用c3p0连接池,解决了显示不稳定的问题,但使用几个小时后,竟会将tomcat弄“崩溃”。用户不能访问网页。错误消息也看不到。网页进行到38%的时候,竟然不动了。
2)在tomcat不能访问情况下,apache上的php网站仍能正常运行。tomcat问题。把tomcat从5.5.20换成了5.0.28也解决不了问题.


<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

<session-factory>
	<property name="connection.username">root</property>
	<property name="connection.password"></property>
	<property name="connection.url">
		jdbc:mysql://localhost/backup?useUnicode=true&amp;characterEncoding=UTF-8
	</property>
	<property name="dialect">
		org.hibernate.dialect.MySQLDialect
	</property>
	<property name="myeclipse.connection.profile">Mysql</property>
	<property name="connection.driver_class">
		com.mysql.jdbc.Driver
	</property>

	<!-- Echo all executed SQL to stdout -->
	<property name="show_sql">true</property>
	<property name="hibernate.jdbc.fetch_size">50</property>
	<property name="hibernate.jdbc.batch_size">25</property>

   <property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
  <property name="hibernate.c3p0.max_size">20</property>
  <property name="hibernate.c3p0.min_size">5</property>
  <property name="hibernate.c3p0.timeout">15000</property>
  <property name="hibernate.c3p0.max_statements">100</property>
  <property name="hibernate.c3p0.idle_test_period">120</property>
  <property name="hibernate.c3p0.acquire_increment">2</property>
  <property name="hibernate.c3p0.validate">true</property>

	<!-- mapping resource="com/voff/News.hbm.xml" /-->
	<mapping resource="com/voff/News.hbm.xml" />
	<mapping resource="com/voff/User.hbm.xml" />
	<mapping resource="com/voff/Comment.hbm.xml" />
	<mapping resource="com/voff/Category.hbm.xml" />
	<mapping resource="com/voff/Pk.hbm.xml" />
	<mapping resource="com/voff/Qa.hbm.xml" />
	<mapping resource="com/voff/Logs.hbm.xml" />
</session-factory>

</hibernate-configuration>


最后感叹一下:
java的开发速度真是折磨人(java菜鸟)。php快捷稳定高效,开发速度又快,真是哀叹。希望自己快点把这个问题解决。
分享到:
评论
13 楼 voff12 2007-04-01  
jamesby 写道
我的意思是你的应用程序产生的各种异常是怎么处理的?
没有log到文件里面?
没有log到文件里。
12 楼 jamesby 2007-04-01  
我的意思是你的应用程序产生的各种异常是怎么处理的?
没有log到文件里面?
11 楼 voff12 2007-03-31  
jamesby 写道
我说的是为你的tomcat配置了多少内存

没有使用Log4j等log工具将你的应用程序出现的异常log到文件里面吗?
我的意思是你看看你的应用程序的日志文件,而不是出现问题的时候去看console!

看log是确认在你出现问题之前是否会有些意料之外的异常出现,我遇到过一次,程序不停的抛出NullPointer异常结果web服务器down掉。

因为servlet是基于线程池的,我在使用sychronized的时候遇到问题,在sychronized处死锁导致web服务器停止响应,估计当时就是线程池里面的所有线程都在sychronized等待。
谢谢楼上热心的回答。但我还未得要领。tomcat是默认配置。应用程序的日志文件是指什么?
sychronized处死锁如何解决呢?
我现在在用同样的程序,同样的运行环境。在另外一台普遍PC机做测试,5个小时了,还没出现崩溃的现象。
10 楼 jamesby 2007-03-31  
我说的是为你的tomcat配置了多少内存

没有使用Log4j等log工具将你的应用程序出现的异常log到文件里面吗?
我的意思是你看看你的应用程序的日志文件,而不是出现问题的时候去看console!

看log是确认在你出现问题之前是否会有些意料之外的异常出现,我遇到过一次,程序不停的抛出NullPointer异常结果web服务器down掉。

因为servlet是基于线程池的,我在使用sychronized的时候遇到问题,在sychronized处死锁导致web服务器停止响应,估计当时就是线程池里面的所有线程都在sychronized等待。
9 楼 voff12 2007-03-31  
谢谢。配置了多少内存,是什么意思?为mysql或tomcat分配的最大内存?主机2G内存。
引用

做个测试,弄一个不访问数据库的页面,在出现问题的时候访问该页面,看是否能够正常访问

tomcat启动后,可以正常运行一段时间。但一段时间内,就崩溃了。所有页面(没有数据库的)页面也不能访问。
引用
用程序日志

卡在38%,浏览器上就不动了。无法看到出错异常。浏览器功能正常。
8 楼 jamesby 2007-03-31  
另外你配置了多少内存,一般情访问量过大,内存过小或者死锁才会出现你说的这种情况。

还有看看你的应用程序日志,是否抛出了过多的意外异常,就是非checked,也非意料之中的异常,异常也可能导致服务器瘫痪。
7 楼 jamesby 2007-03-31  
我觉得可以做个测试,弄一个不访问数据库的页面,在出现问题的时候访问该页面,看是否能够正常访问?

以确认问题出现在哪里?

6 楼 voff12 2007-03-31  
在windows下一直运行良好,不知为何在linux下运行会出现这种效果!
5 楼 voff12 2007-03-31  
好的,我换一个连接池试试。谢谢。下面是我的tomcat日志
localhost_log.2007-03-31.txt

2007-03-31 15:08:41 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2007-03-31 15:08:41 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2007-03-31 15:08:41 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2007-03-31 15:08:41 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2007-03-31 15:08:41 StandardContext[/servlets-examples]SessionListener: contextInitialized()
2007-03-31 15:08:42 StandardContext[/yahoo]org.tuckey.web.filters.urlrewrite.utils.Log ERROR: logLevelConf: WARN
2007-03-31 15:08:45 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@e576d4')
2007-03-31 15:08:45 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1db5ec')
2007-03-31 15:08:45 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@92b1a1')
2007-03-31 15:08:45 StandardContext[/servlets-examples]SessionListener: contextDestroyed()
2007-03-31 15:08:45 StandardContext[/servlets-examples]ContextListener: contextDestroyed()
2007-03-31 15:08:45 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@17918f0')
2007-03-31 15:08:45 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1546dbc')
2007-03-31 15:08:45 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1f08ed8')
2007-03-31 15:08:45 StandardContext[/jsp-examples]SessionListener: contextDestroyed()
2007-03-31 15:08:45 StandardContext[/jsp-examples]ContextListener: contextDestroyed()
2007-03-31 15:11:30 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
2007-03-31 15:11:30 StandardContext[/jsp-examples]ContextListener: contextInitialized()
2007-03-31 15:11:30 StandardContext[/jsp-examples]SessionListener: contextInitialized()
2007-03-31 15:11:31 StandardContext[/servlets-examples]ContextListener: contextInitialized()
2007-03-31 15:11:31 StandardContext[/servlets-examples]SessionListener: contextInitialized()
2007-03-31 15:11:31 StandardContext[/yahoo]org.tuckey.web.filters.urlrewrite.utils.Log ERROR: logLevelConf: WARN
2007-03-31 15:11:35 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1e0512a')
2007-03-31 15:11:35 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1f0aecc')
2007-03-31 15:11:35 StandardContext[/servlets-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@64023c')
2007-03-31 15:11:35 StandardContext[/servlets-examples]SessionListener: contextDestroyed()
2007-03-31 15:11:35 StandardContext[/servlets-examples]ContextListener: contextDestroyed()
2007-03-31 15:11:35 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1c1ac46')
2007-03-31 15:11:35 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1557c0')
2007-03-31 15:11:35 StandardContext[/jsp-examples]ContextListener: attributeReplaced('org.apache.catalina.WELCOME_FILES', '[Ljava.lang.String;@1342a67')
2007-03-31 15:11:35 StandardContext[/jsp-examples]SessionListener: contextDestroyed()
2007-03-31 15:11:35 StandardContext[/jsp-examples]ContextListener: contextDestroyed()
4 楼 ahuaxuan 2007-03-31  
voff12 写道
hibernate3.1说不支持dbcp了。
这怎么可能,我现在还在用3.1.3呢
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.6.5
Created-By: 1.4.2_09-b05 (Sun Microsystems Inc.)
Hibernate-Version: 3.1.3


datasource的配置
引用

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driverClassName}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="maxActive" value="100"/>
        <property name="maxIdle" value="30"/>
        <property name="maxWait" value="1000"/>
           </bean>

如果实在找不出原因,建议换dbcp试试
3 楼 voff12 2007-03-31  
hibernate3.1说不支持dbcp了。
2 楼 ahuaxuan 2007-03-31  
没有异常吗,tomcat控制台有没有异常呢,还有就是再试试其他连接池,还有dbcp你没有试呢
1 楼 voff12 2007-03-31  
希望得到。谢谢!

相关推荐

Global site tag (gtag.js) - Google Analytics