SHARE
TWEET

Untitled

a guest Mar 20th, 2016 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. WARNING:   The web application [] 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.
  2. SEVERE:   The web application [] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal@1087985b]) and a value of type [org.hibernate.internal.SessionImpl] (value [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[] unresolvedInsertDependencies=UnresolvedEntityInsertActions[]])]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
  3. SEVERE:   The web application [] created a ThreadLocal with key of type [net.sf.json.AbstractJSON$1] (value [net.sf.json.AbstractJSON$1@362386d7]) and a value of type [java.util.HashSet] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
  4. SEVERE:   The web application [] created a ThreadLocal with key of type [net.sf.json.AbstractJSON$1] (value [net.sf.json.AbstractJSON$1@362386d7]) and a value of type [java.util.HashSet] (value [[]]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
  5.    
  6. <hibernate-configuration>
  7.  
  8.     <session-factory>
  9.  
  10.         <!-- Database connection settings -->
  11.         <property name="connection.driver_class">
  12.             com.mysql.jdbc.Driver
  13.         </property>
  14.         <property name="connection.url">
  15.             jdbc:mysql://localhost:3306/myproject
  16.         </property>
  17.         <property name="connection.username">root</property>
  18.         <property name="connection.password"></property>
  19.  
  20.         <!-- JDBC connection pool (use the built-in) -->
  21.         <property name="connection.pool_size">12</property>
  22.  
  23.         <!-- SQL dialect -->
  24.         <property name="dialect">
  25.             org.hibernate.dialect.MySQLDialect
  26.         </property>
  27.  
  28.  
  29.  
  30.         <!-- Enable Hibernate's automatic session context management -->
  31.         <property name="current_session_context_class">thread</property>
  32.  
  33. <!--         Disable the second-level cache -->
  34.  
  35. <!-- <property name="cache.provider_class">
  36.             org.hibernate.cache.EhCacheProvider
  37.         </property>
  38.  
  39.         <property name="hibernate.cache.use_query_cache">true</property>-->
  40.  
  41.  
  42.         <!-- Echo all executed SQL to stdout -->
  43.         <property name="show_sql">true</property>
  44.    
  45. public class HibernateUtil {
  46.  
  47.    private static ServiceRegistry serviceRegistry;
  48.    private static final ThreadLocal<Session> threadLocal = new ThreadLocal();
  49.    private static SessionFactory sessionFactory;
  50.  
  51.    private static SessionFactory configureSessionFactory() {
  52.         try {
  53.             Configuration configuration = new Configuration();
  54.             configuration.configure();
  55.             serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
  56.  
  57.             sessionFactory = configuration.buildSessionFactory(serviceRegistry);
  58.  
  59.             return sessionFactory;
  60.         } catch (HibernateException e) {
  61.             System.out.append("** Exception in SessionFactory **");
  62.             e.printStackTrace();
  63.         }
  64.        return sessionFactory;
  65.   }    
  66.  
  67.   static {
  68.     try {
  69.       sessionFactory = configureSessionFactory();
  70.     } catch (Exception e) {
  71.       System.err.println("%%%% Error Creating SessionFactory %%%%");
  72.       e.printStackTrace();
  73.     }
  74.   }
  75.  
  76.   private HibernateUtil() {
  77.   }
  78.  
  79.   public static SessionFactory getSessionFactory() {
  80.     return sessionFactory;
  81.   }
  82.  
  83.   public static Session getSession() throws HibernateException {
  84.     Session session = threadLocal.get();
  85.  
  86.     if (session == null || !session.isOpen()) {
  87.       if (sessionFactory == null) {
  88.         rebuildSessionFactory();
  89.       }
  90.       session = (sessionFactory != null) ? sessionFactory.openSession() : null;
  91.       threadLocal.set(session);
  92.     }
  93.  
  94.     return session;
  95.   }
  96.  
  97.   public static void rebuildSessionFactory() {
  98.     try {
  99.       sessionFactory = configureSessionFactory();
  100.     } catch (Exception e) {
  101.       System.err.println("%%%% Error Creating SessionFactory %%%%");
  102.       e.printStackTrace();
  103.     }
  104.   }
  105.  
  106.   public static void closeSession() throws HibernateException {
  107.     Session session = (Session) threadLocal.get();
  108.     threadLocal.set(null);
  109.  
  110.     if (session != null) {
  111.       session.close();
  112.     }
  113.   }
  114. }
  115.    
  116. String url = "your JDBC url";
  117. Driver driver = DriverManager.getDriver(url);
  118. DriverManager.deregisterDriver(driver);
  119.    
  120. public class CleanupListener implements ServletContextListener {
  121.  
  122.     public void contextDestroyed(ServletContextEvent arg0) {
  123.         // enter cleanup code here
  124.     }
  125.  
  126.     public void contextInitialized(ServletContextEvent arg0) { }
  127. }
  128.    
  129. <listener>
  130.     <listener-class>com.example.CleanupListener</listener-class>
  131. </listener>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top