0

I'm devoloping an Spring 4 Based WebApp for managing fitness training. For the persistence layer i use Hibernate 4.3.5.

Everything worked fine so far,then i deployed my App to my Tomcat Server, running on a Synology NAS, for testing purpose. After ~2 hours i get the following Errors from the log:

Jun 17, 2014 1:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/trainingsmanager] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jun 17, 2014 1:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/trainingsmanager] appears to have started a threadnamed [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.

I think this is a problem with my Hibernate config or with my Data classes.

servlet-context.xml :

    <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        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
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"
    xmlns:tx="http://www.springframework.org/schema/tx">
    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->

    <beans:bean id="tilesViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass">
            <beans:value>
                org.springframework.web.servlet.view.tiles3.TilesView
            </beans:value>
        </beans:property>
    </beans:bean>

    <beans:bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>/WEB-INF/tiles.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>

    <context:component-scan base-package="de.jupdi.trainingsmanager" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.controller" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.dao" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.entity" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.helper" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.service" />
    <context:component-scan base-package="de.jupdi.trainingsmanager.form" />


    <!-- JDBC Data Source. It is assumed you have MySQL running on localhost 
        port 3306 with username root and blank password. Change below if it's not 
        the case -->
    <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <beans:property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <beans:property name="url"
            value="jdbc:mysql://localhost:3306/trainingsmanager" />
        <beans:property name="username" value="root" />
        <beans:property name="password" value="" />
        <beans:property name="validationQuery" value="SELECT 1" />
        <beans:property name="removeAbandoned" value="true" />
        <beans:property name="removeAbandonedTimeout" value="60" />
    </beans:bean>

    <!-- Hibernate Session Factory -->
    <beans:bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <beans:property name="dataSource" ref="dataSource" />
        <beans:property name="packagesToScan">
            <beans:array>
                <beans:value>de.jupdi.trainingsmanager</beans:value>
            </beans:array>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:value>
                hibernate.dialect=org.hibernate.dialect.MySQLDialect
                hibernate.connection.release_mode=auto
            </beans:value>
        </beans:property>
    </beans:bean>

    <!-- Hibernate Transaction Manager -->
    <beans:bean id="transactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>
    <tx:annotation-driven />

    <beans:bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <beans:property name="basename" value="messages" />
    </beans:bean>

    <beans:bean id="userService"
        class="org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl">
        <beans:property name="dataSource" ref="dataSource" />
    </beans:bean>
    <tx:annotation-driven transaction-manager="transactionManager"  />



    <!-- Own Beans -->

    <beans:bean id="routineManager"
        class="de.jupdi.trainingsmanager.service.RoutineManagerImpl" />
    <beans:bean id="planManager"
        class="de.jupdi.trainingsmanager.service.PlanManagerImpl" />
    <beans:bean id="trainingManager"
        class="de.jupdi.trainingsmanager.service.TrainingManagerImpl" />
    <beans:bean id="unitManager"
        class="de.jupdi.trainingsmanager.service.UnitManagerImpl" />
    <beans:bean id="userManager"
        class="de.jupdi.trainingsmanager.service.UserManagerImpl" />
    <beans:bean id="resultManager"
        class="de.jupdi.trainingsmanager.service.ResultManagerImpl" />
    <beans:bean id="roleManager"
        class="de.jupdi.trainingsmanager.service.RoleManagerImpl" />

    <beans:bean id="routineDAO"
        class="de.jupdi.trainingsmanager.dao.RoutineDAOImpl" />
    <beans:bean id="unitDAO" class="de.jupdi.trainingsmanager.dao.UnitDAOImpl" />
    <beans:bean id="resultDAO" class="de.jupdi.trainingsmanager.dao.ResultDAOImpl" />
    <beans:bean id="planDAO" class="de.jupdi.trainingsmanager.dao.PlanDAOImpl" />
    <beans:bean id="trainingDAO"
        class="de.jupdi.trainingsmanager.dao.TrainingDAOImpl" />
    <beans:bean id="userDAO" class="de.jupdi.trainingsmanager.dao.UserDAOImpl" />
    <beans:bean id="roleDAO" class="de.jupdi.trainingsmanager.dao.RoleDAOImpl" />

    <beans:bean id="customUserDetailsService"
        class="de.jupdi.trainingsmanager.service.CustomUserDetailsService" />

</beans:beans>

web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/*-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
    </filter>
    <filter-mapping>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>


    <filter>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <filter-class>org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>OpenSessionInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

Here is one example how i store and load data:

TrainingDAOImpl.java:

package de.jupdi.trainingsmanager.dao;

import java.util.Date;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import de.jupdi.trainingsmanager.entity.PlanEntity;
import de.jupdi.trainingsmanager.entity.TrainingEntity;
import de.jupdi.trainingsmanager.entity.UnitEntity;

public class TrainingDAOImpl implements TrainingDAO {

    @Autowired
    SessionFactory sessionFactory;

    @Override
    public void addTraining(TrainingEntity training) {
        this.sessionFactory.getCurrentSession().save(training);
    }

    @Override
    public TrainingEntity getTraining(Integer trainingId) {
        return (TrainingEntity) this.sessionFactory.getCurrentSession().get(TrainingEntity.class, trainingId);
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings() {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity").list();
    }

    @Override
    public void deleteTraining(Integer trainingId) {
        this.sessionFactory.getCurrentSession().delete((TrainingEntity) this.sessionFactory.getCurrentSession().load(TrainingEntity.class, trainingId));
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings(Integer user) {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity where user="+ user).list();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings(Integer user, Date date) {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity where user="+ user +" and date="+date.toString()).list();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings(Integer user, Date dateStart,
            Date dateStop) {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity where user="+ user +" and date is between "+ dateStart.toString() +" and "+ dateStop.toString()).list();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings(Integer user, UnitEntity unit) {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity where user="+ user + " and unit=" + unit.getId()).list();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<TrainingEntity> getAllTrainings(Integer user, PlanEntity plan) {
        return this.sessionFactory.getCurrentSession().createQuery("from TrainingEntity where user="+ user + " and plan=" + plan.getId()).list();
    }

}

TrainingEntity.java:

package de.jupdi.trainingsmanager.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="training")
public class TrainingEntity {

    @Id
    @Column(name="id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int id;

    @Column(name="user")
    private Integer user;

    @Column(name="date")
    private Date date;

    @Column(name="plan")
    private Integer plan;

    @Column(name="unit")
    private Integer unit;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Integer getUser() {
        return user;
    }

    public void setUser(Integer user) {
        this.user = user;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date2) {
        this.date = date2;
    }

    public Integer getPlan() {
        return plan;
    }

    public void setPlan(Integer plan) {
        this.plan = plan;
    }

    public Integer getUnit() {
        return unit;
    }

    public void setUnit(Integer unitId) {
        this.unit = unitId;
    }

}

TrainingManager.java:

package de.jupdi.trainingsmanager.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import de.jupdi.trainingsmanager.dao.TrainingDAO;
import de.jupdi.trainingsmanager.entity.TrainingEntity;
import de.jupdi.trainingsmanager.entity.UnitEntity;

@Service
public class TrainingManagerImpl implements TrainingManager {

    @Autowired
    TrainingDAO trainingDAO;

    @Override
    @Transactional
    public void addTraining(TrainingEntity training) {
        trainingDAO.addTraining(training);
    }

    @Override
    @Transactional
    public TrainingEntity getTraining(Integer trainingId) {
        return trainingDAO.getTraining(trainingId);
    }

    @Override
    @Transactional
    public List<TrainingEntity> getAllTrainings() {
        return trainingDAO.getAllTrainings();
    }

    @Override
    @Transactional
    public List<TrainingEntity> getAllTrainings(Integer user) {
        return trainingDAO.getAllTrainings(user);
    }

    @Override
    @Transactional
    public List<TrainingEntity> getAllTrainings(Integer user, Date date) {
        return trainingDAO.getAllTrainings(user, date);
    }

    @Override
    @Transactional
    public List<TrainingEntity> getAllTrainings(Integer user, Date dateStart,
            Date dateStop) {
        return trainingDAO.getAllTrainings(user, dateStart, dateStop);
    }

    @Override
    @Transactional
    public List<TrainingEntity> getAllTrainings(Integer user, UnitEntity unit) {
        return trainingDAO.getAllTrainings(user, unit);
    }

    @Override
    @Transactional
    public void deleteTraining(Integer TrainingId) {
        trainingDAO.deleteTraining(TrainingId);
    }

}

I hope i gave enough information so you can help me :)

Thanks Jupdi

Localhost.log:

Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jun 17, 2014 1:49:04 PM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jun 17, 2014 1:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/trainingsmanager] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Jun 17, 2014 1:49:04 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/trainingsmanager] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8080"]
Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8080"]
Jun 17, 2014 1:49:04 PM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]
Jupdi
  • 23
  • 7
  • 3
    The error *... registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. ...* is not really serious by itself ... but what is interesting is what happened before : tomcat is stopping your application BEFORE displaying this message. – Serge Ballesta Jul 07 '14 at 17:07
  • can you ping what exception you are getting in localhost.log file. – Radha Mohan Maheshwari Jul 07 '14 at 17:08
  • Tranks. Added the log, but it doesnt give more information – Jupdi Jul 07 '14 at 18:18
  • Your application seems to be stopped but before that even the tomcat service seemed to be stopped "INFO: Stopping service Catalina". Was your server stopped by any means before that. What are your memory settings ? Try running the server again with jvisualvm (shipped with JDK) attached to it. Next time it happens you can have a visual information of the memory utilization and you can even run the sampler to track the excessive objects created on heap. – Shailendra Jul 07 '14 at 18:28
  • Just move your driver to tomcat lib/ folder, and exclude it from your app. http://wiki.apache.org/tomcat/MemoryLeakProtection#jdbc – white Jul 07 '14 at 18:29
  • Moved the mysql driver to the lib/ folder, but i didn't help. Still getting the same errors. I will try it with jvisualvm. – Jupdi Jul 08 '14 at 13:47
  • The same issue was addressed [here][1] and answered. [1]: http://stackoverflow.com/questions/3320400/to-prevent-a-memory-leak-the-jdbc-driver-has-been-forcibly-unregistered – ethesx Jun 11 '15 at 15:00

0 Answers0