【问题标题】:Long delay in server startup time服务器启动时间延迟长
【发布时间】:2016-07-25 04:11:07
【问题描述】:

使用 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, 休眠版本:4.2.7.Final

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

【问题讨论】:

  • 查看日志似乎在启动期间发生了一些删除、更新和插入。如果是这样,您能否提供一些有关该应用程序在启动期间正在做什么的信息?还发布您的 persistence.xml 文件可能会有所帮助。
  • 对于初学者,请禁用日志记录,因为日志记录很慢并且确实会减慢应用程序的启动速度。
  • @MadhusudanaReddySunnapu 我正在使用 java 配置,您可以在 stackoverflow.com/questions/36304458/… 看到我的 java 配置。不使用单独的 persistence.xml。更何况我在启动时没有配置任何东西。

标签: spring hibernate jersey tomcat7


【解决方案1】:

尝试在persistence.xml 内部的持久性单元配置中添加此属性:

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

它通常会加速休眠。

2016-04-14 附加一个“s”来更正属性名称。

【讨论】:

  • 已经试过了,没有改善。你可以在stackoverflow.com/questions/36304458/…看到我的配置。
  • 在additionalProperties方法中我添加了properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults","false");
  • 你使用'org.hibernate.jpa.HibernatePersistenceProvider'作为提供者对吗?同时发布您的休眠配置类/文件
  • 正如您在我的配置中看到的那样,没有特定的休眠配置类/文件。我通过 pooledDataSource() 方法设置所有这些。
  • 最初我没有使用“org.hibernate.jpa.HibernatePersistenceProvider”。所以在配置中添加代码为'entityManagerFactory.setPersistenceProviderClass(org.hibernate.jpa.HibernatePersistenceProvider.class);'
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-18
  • 2015-08-28
  • 1970-01-01
  • 2019-02-20
  • 2021-05-24
  • 2013-11-07
  • 1970-01-01
相关资源
最近更新 更多