java H2挂在arm32设备上的getLocalhost

时间:2017-03-27 19:57:30

标签: java localhost h2

我的应用程序在Windows,OSX和Ubuntu以及其他版本的linux 到目前为止都能正常运行。

在使用jdk-8u121-linux-arm32-vfp-hflt.tar.gz的arm 32机器上,尝试使用纯Java数据库H2创建Hibernate数据库然后放弃

,它挂了五分钟
public static void recreateDatabase()
    {
        Configuration config;
        config =
                HibernateUtil.getInitializedConfigurationAndRebuildAuditTables();
        new SchemaExport(config).create(false,true);
        factory = config.buildSessionFactory();
    }

我在这期间运行jstack,相关的线程我认为关键的一个是列在第二个列在 java.net.Inet4AddressImpl.lookupAllHostAddr 但它似乎只是试图获得localhost ,该机器实际上是一个嵌入式设备,我想知道这是否意味着它有可能导致问题的奇怪网络?

我已经更新到最新版本的h2(1.4.194),并且我可以使用最新版本的hibernate而不需要更改代码(4.3.11.Final),因为之后他们对SchemaExport进行了更改。

"main" #1 prio=5 os_prio=0 tid=0xb6105890 nid=0x7580 in Object.wait() [0xb6336000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x7c042900> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1414)
        at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
        - locked <0x7c042900> (a com.mchange.v2.resourcepool.BasicResourcePool)
        at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682)
        at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
        at org.hibernate.c3p0.internal.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:90)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279)
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1930)
        at com.jthink.songlayer.hibernate.HibernateUtil.recreateDatabase(HibernateUtil.java:135)
        at com.jthink.songkong.cmdline.CmdCreateDatabase.start(CmdCreateDatabase.java:27)
        at com.jthink.songkong.cmdline.SongKong.cmdCheckDatabase(SongKong.java:1904)
        at com.jthink.songkong.cmdline.SongKong.cmdlineStart(SongKong.java:1574)
        at com.jthink.songkong.cmdline.SongKong.finish(SongKong.java:1699)
        at com.jthink.songkong.cmdline.SongKongForMelco.main(SongKongForMelco.java:33)

在这5分钟的时间内运行jstack我看到了:

"C3P0PooledConnectionPoolManager[identityToken->tys5dp9n86d1sl8vqh|f278eb]-HelperThread-#0" #9 daemon prio=5 os_prio=0 tid=0x7a1747b8 nid=0x75d3 runnable [0x79d60000]
       java.lang.Thread.State: RUNNABLE
            at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
            at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
            at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
            at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
            - locked <0x8eddfe38> (a java.lang.Object)
            at org.h2.util.NetUtils.getLocalAddress(NetUtils.java:272)
            - locked <0x7c040f80> (a java.lang.Class for org.h2.util.NetUtils)
            at org.h2.store.FileLock.lockSocket(FileLock.java:380)
            at org.h2.store.FileLock.lock(FileLock.java:138)
            - locked <0x7be62750> (a org.h2.store.FileLock)
            at org.h2.engine.Database.open(Database.java:662)
            - locked <0x7bc23a90> (a org.h2.engine.Database)
            at org.h2.engine.Database.openDatabase(Database.java:276)
            at org.h2.engine.Database.<init>(Database.java:270)
            at org.h2.engine.Engine.openSession(Engine.java:64)
            at org.h2.engine.Engine.openSession(Engine.java:176)
            - locked <0x8ee8bc50> (a org.h2.engine.Engine)
            at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
            at org.h2.engine.Engine.createSession(Engine.java:137)
            at org.h2.engine.Engine.createSession(Engine.java:27)
            at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
            at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
            at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
            at org.h2.Driver.connect(Driver.java:69)
            at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
            at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
            at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
            at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
            at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)

然后使用

创建一些线程
"C3P0PooledConnectionPoolManager[identityToken->tys5dp9n86d1sl8vqh|f278eb]-HelperThread-#2" #11 daemon prio=5 os_prio=0 tid=0x7a312eb0 nid=0x75d5 waiting for monitor entry [0x79c]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at org.h2.engine.Engine.openSession(Engine.java:169)
        - waiting to lock <0x8ee8bc50> (a org.h2.engine.Engine)
        at org.h2.engine.Engine.createSessionAndValidate(Engine.java:154)
        at org.h2.engine.Engine.createSession(Engine.java:137)
        at org.h2.engine.Engine.createSession(Engine.java:27)
        at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:354)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:116)
        at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:100)
        at org.h2.Driver.connect(Driver.java:69)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:146)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:195)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:184)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1086)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1073)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
        at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1810)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:648)

使用网络信息进行更新

more /etc/hosts

127.0.0.1       localhost

more /etc/resolv.conf

# Generated by dhcpcd for interface br0
nameserver 192.168.0.1

更新

刚刚向我指出问题是 H2 而不是** Hibernate,可以修改为使用不同的方法,它是在其NetUtils类中进行调用的H2

1 个答案:

答案 0 :(得分:0)

我通过将此h2属性添加到我的HibernateUtil配置

来修复
System.setProperty("h2.bindAddress", InetAddress.getLoopbackAddress().getHostAddress());

我只是希望它不会打破任何当前的工作安装!