2016-04-05 138 views
0

使用Spring,Hibernate和Jersey与现有应用程序并行开发Web服务。最初我使用的实体类少于20个,服务器启动时间少于45秒。现在我添加了所有191个实体类,我将在稍后的时间点使用它。添加完这些应用程序后,我们需要将近7分钟才能启动。顺便说一句,我使用Tomcat 7作为我的服务器。服务器启动时间长延迟

在日志中我可以看到很多

o.h.ejb.packaging.AbstractJarVisitor - Filtering:............ 

o.h.cfg.annotations.CollectionBinder - Collection role:....... 
o.h.cfg.annotations.PropertyBinder - Building property....... 
org.hibernate.cfg.Ejb3Column - Binding column: Ejb3JoinColumn{.... 
org.hibernate.cfg.Ejb3Column - Binding column: Ejb3Column{table..... 

o.h.c.annotations.SimpleValueBinder - Setting SimpleValue typeName for ..... 

o.hibernate.cfg.CollectionSecondPass - Second pass for collection:...... 
o.h.cfg.annotations.CollectionBinder - Binding a OneToMany: ..... 
o.h.cfg.annotations.CollectionBinder - Mapping collection: ..... 
o.h.cfg.annotations.TableBinder - Retrieving property ...... 

org.hibernate.cfg.Configuration - Resolving reference to class: ..... 

o.h.c.e.AbstractEhcacheRegionFactory - HHH020003: Could not find a specific ehcache configuration for cache named [.....]; using defaults. 
net.sf.ehcache.Cache - Initialised cache: ..... 
n.s.e.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for '..... 
o.h.c.e.AbstractEhcacheRegionFactory - started EHCache region:.... 
o.h.p.entity.AbstractEntityPersister - Static SQL for entity:..... 
o.h.p.entity.AbstractEntityPersister - Version select: ..... 
o.h.p.entity.AbstractEntityPersister - Snapshot select:.... 
o.h.p.entity.AbstractEntityPersister - Insert 0: ..... 
o.h.p.entity.AbstractEntityPersister - Update 0: .... 
o.h.p.entity.AbstractEntityPersister - Delete 0: .... 

o.h.p.c.AbstractCollectionPersister - Static SQL for collection:..... 
o.h.p.c.AbstractCollectionPersister - Row insert: ..... 
o.h.p.c.AbstractCollectionPersister - Row update: ..... 
o.h.p.c.AbstractCollectionPersister - Row delete: ..... 
o.h.p.c.AbstractCollectionPersister - One-shot delete: .... 

我发现以下的正在采取大量的时间

org.hibernate.loader.Loader - Static select for entity ... [NONE]: ... 
org.hibernate.loader.Loader - Static select for entity ... [READ]: ... 
org.hibernate.loader.Loader - Static select for entity ... [UPGRADE]: ... 
org.hibernate.loader.Loader - Static select for entity ... [UPGRADE_NOWAIT]: ... 
org.hibernate.loader.Loader - Static select for entity ... [FORCE]: ... 
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_READ]: ... 
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_WRITE]: ... 
org.hibernate.loader.Loader - Static select for entity ... [PESSIMISTIC_FORCE_INCREMENT]: ... 
org.hibernate.loader.Loader - Static select for entity ... [OPTIMISTIC]: ... 
org.hibernate.loader.Loader - Static select for entity ... [OPTIMISTIC_FORCE_INCREMENT]: ... 
org.hibernate.loader.Loader - Static select for action ACTION_MERGE on entity ... : ... 
org.hibernate.loader.Loader - Static select for action ACTION_REFRESH on entity ...: ... 

o.h.l.collection.OneToManyLoader - Static select for one-to-many 

如何提高启动时间?

注意:在使用Spring版本:4.1.4.RELEASE, Hibernate的版本:4.2.7.Final

我用java的配置,你可以在spring + hibernate + c3p0 + ehcache java configuration看到我的Java配置。不使用单独的persistence.xml

+0

看着日志,似乎有一些删除,更新和插入在启动过程中发生。如果是这样,你能提供一些关于应用程序在启动过程中所做的一些信息吗?同时发布您的persistence.xml文件可能会有所帮助。 –

+0

对于初学者来说,由于日志记录速度很慢并且确实会减慢应用程序的启动速度,因此禁用日志记录功能。 –

+0

@MadhusudanaReddySunnapu我使用java配置,你可以在http://stackoverflow.com/questions/36304458/spring-hibernate-c3p0-ehcache-java-configuration/36305748看到我的java配置。不使用单独的persistence.xml。更重要的是,我在启动时没有配置任何东西。 –

回答

0

尝试在你的持久化单元配置中添加这个属性,里面persistence.xml

<property name="hibernate.temp.use_jdbc_metadata_defaults" value="false"/> 

它通常加速休眠。

2016-04-14添加“s”以更正属性名称。

+0

已经尝试过,没有任何改进。你可以在http://stackoverflow.com/questions/36304458/spring-hibernate-c3p0-ehcache-java-configuration/36305748看到我的配置。 –

+0

in additionalProperties方法我添加了类似properties.setProperty(“hibernate.temp.use_jdbc_metadata_defaults”,“false”)的代码; –

+0

你使用'org.hibernate.jpa.HibernatePersistenceProvider'作为提供者吗?同样发布你的休眠配置类/文件 –