Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 升级到Hibernate 4.3.4 main方法永不终止JVM未完成_Java_Multithreading_Hibernate_Jpa - Fatal编程技术网

Java 升级到Hibernate 4.3.4 main方法永不终止JVM未完成

Java 升级到Hibernate 4.3.4 main方法永不终止JVM未完成,java,multithreading,hibernate,jpa,Java,Multithreading,Hibernate,Jpa,我必须从hibernate4.2.3升级到hibernate4.3.4来测试一些jpa2.1规范。我只更改了这行code 前一行: final org.hibernate.service.ServiceRegistry serviceRegistry = new org.hibernate.service.ServiceRegistryBuilder().applySettings(hibConfiguration.getProperties()).buildServiceRegistry();

我必须从
hibernate4.2.3
升级到
hibernate4.3.4
来测试一些
jpa2.1
规范。我只更改了这行
code

前一行:

final org.hibernate.service.ServiceRegistry serviceRegistry = new org.hibernate.service.ServiceRegistryBuilder().applySettings(hibConfiguration.getProperties()).buildServiceRegistry();
新添加的代码行

final org.hibernate.service.ServiceRegistry serviceRegistry = new org.hibernate.boot.registry.StandardServiceRegistryBuilder().applySettings(hibConfiguration.getProperties()).build();
问题是,我有一个主要方法只用于测试一些
标准API
,但是
主要方法
永远不会在最新的
Hibernate版本中完成
我检索了正在运行的线程,最新版本的线程如下所示

ThreadList:
[threadID:]2  [threadName:] Reference Handler [isDaemon:] true [isAlive:] true
[threadID:]3  [threadName:] Finalizer [isDaemon:] true [isAlive:] true
[threadID:]4  [threadName:] Signal Dispatcher [isDaemon:] true [isAlive:] true
[threadID:]5  [threadName:] Attach Listener [isDaemon:] true [isAlive:] true
[threadID:]10 [threadName:] Abandoned connection cleanup thread [isDaemon:] true [isAlive:] true
[threadID:]11 [threadName:] pool-1-thread-1 [isDaemon:] false [isAlive:] true
[threadID:]1  [threadName:] main [isDaemon:] false [isAlive:] true
与以前的版本相比,这个线程是新的

[threadID:]11 [threadName:] pool-1-thread-1 [isDaemon:] false [isAlive:] true
根据规范,不是守护进程

No, it is not. The virtual machine terminates if the last non-daemon thread has finished. It doesn't have to be the main thread.
我想这条线至少不会在5分钟内完成

问题只出现在创建HibernateSessionFactory时。

public static void main(String[] args)
{        
    HibernateHandler handler = new HibernateHandler(true);//creates the HibernateSessionFactory
    return;//JVM not finish at this point
}
我希望我的JVM以main方法finish终止


我做错了什么..

要了解线程在做什么,可以进行线程转储,例如,在调试模式下从eclipse运行程序,然后挂起线程


但是在您的特定情况下,您应该尝试调用。

新的
ServiceRegister
似乎没有
关闭
已销毁
会话工厂
关闭时,您必须在调用时自行销毁

getSessionFactory.close().
我的新Hibernate代码

final Configuration hibConfiguration = new Configuration().configure(yourCFGPath);         
final org.hibernate.service.ServiceRegistry serviceRegistry = new org.hibernate.boot.registry
.StandardServiceRegistryBuilder().
applySettings(hibConfiguration.getProperties()).build();
hibConfiguration.setSessionFactoryObserver(new SessionFactoryObserver()
{
    @Override
    public void sessionFactoryCreated(SessionFactory factory){}
    @Override
    public void sessionFactoryClosed(SessionFactory factory)
    {
        ((StandardServiceRegistryImpl)serviceRegistry).destroy();
    }});                
 final org.hibernate.SessionFactory factory = hibConfiguration.buildSessionFactory(serviceRegistry);
以后你得打电话

session.getSessionFactory().close();

我希望真的能帮助别人。

非常感谢。我对此一无所知。为什么hibernate的人总是不喜欢这些东西,并且不提供关于新实现的信息(4.1、4.2、4.3…)。?有空的javadocs很难再次感谢你!