unassuming 2016-05-26 00:15 采纳率: 54.5%
浏览 1205

关于HibernateUtil web项目关闭服务器提示线程关闭失败,然后服务器无法正常关闭

package com.mall.util;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public class HibernateThreadUtil {

private static SessionFactory sessionFactory = buildSessionFactory();

public static final ThreadLocal session = new ThreadLocal();

private static SessionFactory buildSessionFactory(){
try{
Configuration configuration = new Configuration().configure(); // 实例化配置文件

ServiceRegistry serviceRegistry =new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); // 实例化服务登记

sessionFactory = configuration.buildSessionFactory(serviceRegistry); // 获取Session工厂

//sessionFactory = new Configuration().configure().buildSessionFactory();
return sessionFactory;

}catch(Throwable ex){
throw new ExceptionInInitializerError(ex);
}
}

/*static{
try{
Configuration configuration = new Configuration().configure(); // 实例化配置文件

ServiceRegistry serviceRegistry =new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); // 实例化服务登记

sessionFactory = configuration.buildSessionFactory(serviceRegistry); // 获取Session工厂

//sessionFactory = new Configuration().configure().buildSessionFactory();

}catch(Throwable ex){
throw new ExceptionInInitializerError(ex);
}
}*/

/**

  • 获得当前session
  • @return session
  • @throws HibernateException */ public static Session getSession()throws HibernateException{ Session s = (Session)session.get(); if(s==null||!s.isOpen()){ s = sessionFactory.openSession(); session.set(s); } return s; }

/**

  • 回滚
  • */ public static void rollback(Transaction tx){ try{ if(tx!=null){ tx.rollback(); } }catch(HibernateException e){ System.out.println("rollback faild:"+e); } }

/**

  • 关闭session
  • */ public static void closeSession()throws HibernateException{ Session s = (Session)session.get(); session.set(null); if(s!=null){ s.close(); } } }

警告: The web application [Mall] 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.
五月 24, 2016 1:14:40 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [Mall] 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. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.lang.ref.ReferenceQueue.remove(Unknown Source)
com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)
五月 24, 2016 1:14:40 下午 org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
警告: The web application [Mall] appears to have started a thread named [pool-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起