【问题标题】:Tomcat Server Crashed InstantlyTomcat 服务器瞬间崩溃
【发布时间】:2014-01-28 12:08:11
【问题描述】:

当我运行我的应用程序时,Tomcat 服务器立即崩溃。

我用hibernate框架做了一个spring mvc应用程序。我是新的hibernate和spring mvc。

我将我的应用程序部署到了 tomcat 服务器。它只运行很短的时间。

当我要检查 tomcat 日志文件时。

当我的应用程序未加载到 tomcat 服务器时,我收到此错误。

tomcat 服务器中的日志文件

localhost.24-1-14

Jan 28, 2014 4:39:23 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/travellogs] threw exception [Handler processing failed; nested exception is java.lang.OutOfMemoryError: PermGen space] with root cause
java.lang.OutOfMemoryError: PermGen space

有时我收到此错误“连接太多”

我不知道如何解决它。我认为我的代码包含内存泄漏..

这是我的 jdbc.properties 文件

jdbc.driverClassName=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/kqtravellog?autoReconnect=true


jdbc.username=kqtravellog
jdbc.password=123asd!@#


jdbc.maxConnections=25

jdbc.acquireIncrement=5
jdbc.minPoolSize=25
jdbc.maxPoolSize=1000
jdbc.maxIdleTime=36000

jdbc.numHelperThreads=100


# Property that determines the Hibernate dialect
hibernate.dialect=org.hibernate.dialect.MySQLDialect

调度程序小服务程序

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:component-scan base-package="com.kqics" />

    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />

    <bean id="userService" class="com.sample.dao.traveldao">
    </bean>

    <bean id="viewResolver1" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
        <property name="order" value="1"/>
        <property name="basename" value="views"/>
    </bean>

    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">

        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="10000000" />
    </bean>

    <import resource="db-config.xml" />

</beans>

db-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p" 
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location"><value>/WEB-INF/jdbc.properties</value></property>
    </bean>


<bean id="dataSourceBean" lazy-init="true"       class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}" />
        <property name="user" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />


        <property name="acquireIncrement" value="${jdbc.acquireIncrement}" />
        <property name="minPoolSize" value="${jdbc.minPoolSize}" />
        <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
        <property name="maxIdleTime" value="${jdbc.maxIdleTime}" />
        <property name="numHelperThreads" value="${jdbc.numHelperThreads}" />

    </bean>
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
                 p:dataSource-ref="dataSourceBean"
                 p:packagesToScan="com.kqics" >

        <property name="hibernateProperties">
        <props>
        <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <!--   <prop key="hibernate.hbm2ddl.auto">create</prop> --> 
        <prop key="hibernate.show_sql">true</prop>
        </props>
        </property>

    </bean>

    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
    <tx:annotation-driven/>

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ><ref bean="sessionFactory"/></property>

    </bean>


</beans>

这是我的 dao 实现

public class kqtraveldao {

    private HibernateTemplate hibernateTemplate;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        try {
            hibernateTemplate = new HibernateTemplate(sessionFactory);

        } catch (Exception w) {
        }

    }


    @Override
    public void addnewvehicle(kqvehicle obj) {

        hibernateTemplate.save(obj);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<kqvehicle> fetchallvehicle() {

        List<kqvehicle> li=hibernateTemplate.find("from kqvehicle");
        return li;
    }

    @Override
    public void addnewvehicletariff(kqvehicletariff obj, String tariff) {

        try
        {
        hibernateTemplate.getSessionFactory()
        .openSession()
        .createSQLQuery("insert into "+tariff+" values(?,?,?,?,?)")
        .setParameter(0, obj.getTid())
        .setParameter(1, obj.getVehicletype())
        .setParameter(2, obj.getRupees())
        .setParameter(3, obj.getDateupto())
        .setParameter(4, obj.getDatetimedetermined())
        .executeUpdate();
        }
        catch(Exception e)
        {

        }
        finally
        {
            hibernateTemplate.getSessionFactory().close();
        }


    }

服务类

@服务 公共类 kqtravellogservice 实现 ikqtravellogservice {

@Autowired
ikqtraveldao iDao;

@Transactional
public void serviceaddnewvehicle(kqvehicle obj) {
    // TODO Auto-generated method stub

    iDao.addnewvehicle(obj);

}

@Transactional
public List<kqvehicle> servicefetchallvehicle() {

    return iDao.fetchallvehicle();
}

@Transactional
public void serviceaddnewvehicletariff(kqvehicletariff obj,String tariff) {

    iDao.addnewvehicletariff(obj,tariff);

}

}

这些方法是我用来开发应用程序的。

我不知道我在哪里找到内存泄漏..请告诉我.....

【问题讨论】:

标签: spring hibernate spring-mvc tomcat7 hibernate-annotations


【解决方案1】:

您需要做的就是增加您的 PermGen 空间。这很容易。如果您使用的是 Eclipse,只需转到运行 > 运行配置。选择您的服务器,转到参数并将其放在后面:

-XX:MaxPermSize=512m

【讨论】:

    猜你喜欢
    • 2017-07-29
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多