2016-04-05 209 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'作爲提供者嗎?同樣發佈你的休眠配置類/文件 –