例如这样做有什么好处:
2015-06-01 16:39:35.102+0000 ERROR [o.n.s.CommunityBootstrapper]: Failed to start Neo Server on port [7474]
org.neo4j.server.ServerStartupException: Starting Neo4j Server failed: Component 'org.neo4j.server.database.LifecycleManagingDatabase@6d7232a5' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:255) ~[neo4j-server-2.2.2.jar:2.2.2]
at org.neo4j.server.Bootstrapper.start(Bootstrapper.java:117) [neo4j-server-2.2.2.jar:2.2.2]
at org.neo4j.server.Bootstrapper.main(Bootstrapper.java:69) [neo4j-server-2.2.2.jar:2.2.2]
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.server.database.LifecycleManagingDatabase@6d7232a5' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:513) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.server.AbstractNeoServer.start(AbstractNeoServer.java:203) ~[neo4j-server-2.2.2.jar:2.2.2]
... 2 common frames omitted
Caused by: java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /data/neo4j
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:334) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:59) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.server.database.LifecycleManagingDatabase$1.newGraphDatabase(LifecycleManagingDatabase.java:44) ~[neo4j-server-2.2.2.jar:2.2.2]
at org.neo4j.server.database.LifecycleManagingDatabase.start(LifecycleManagingDatabase.java:110) ~[neo4j-server-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:507) ~[neo4j-kernel-2.2.2.jar:2.2.2]
... 4 common frames omitted
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.state.DataSourceManager@7aff1fa3' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:513) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330) ~[neo4j-kernel-2.2.2.jar:2.2.2]
... 8 common frames omitted
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.NeoStoreDataSource@5db7419c' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:513) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:117) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:507) ~[neo4j-kernel-2.2.2.jar:2.2.2]
... 10 common frames omitted
Caused by: org.neo4j.kernel.impl.storemigration.StoreUpgrader$UpgradingStoreVersionNotFoundException: 'neostore.nodestore.db' does not contain a store version, please ensure that the original database was shut down in a clean state.
at org.neo4j.kernel.impl.storemigration.UpgradableDatabase.checkUpgradeable(UpgradableDatabase.java:86) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.impl.storemigration.StoreMigrator.needsMigration(StoreMigrator.java:158) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.getParticipantsEagerToMigrate(StoreUpgrader.java:259) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.migrateIfNeeded(StoreUpgrader.java:134) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.NeoStoreDataSource.upgradeStore(NeoStoreDataSource.java:560) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:461) ~[neo4j-kernel-2.2.2.jar:2.2.2]
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:507) ~[neo4j-kernel-2.2.2.jar:2.2.2]
... 13 common frames omitted
而不是这样做:
class SomeClass
{
private static final SimpleDateFormat yyyyMMddFormat = new SimpleDateFormat("yyyy-MM-dd");
}
答案 0 :(得分:1)
在块中,如果初始化不是那么简单,也可以进行一些处理。如果您正在初始化集合,请使用它。
static{
for(int i = 0; i< 100; i++){
// new stuff
}
}
你不能从内联那里做到这一点。
就内联方式而言,如果你不需要额外的处理,它看起来更干净。