VIRGIN FOREST OF JAVA
          不要埋頭苦干,要學(xué)習(xí),學(xué)習(xí),再學(xué)習(xí)。。。。。
          powered by R.Zeus

          From: Performance: Hibernate startup time

          The following tips hints how to make Hibernate startup faster.

          Only add the mapping files you need!

          If you are running some few JUnit tests for a 400++ classes project you probably don't hit every class in those tests and thus do not need to add all those hbm.xml's to the Configuration. Go look at Hibernate's test suite on how you could let your TestCase decide what classes should be defined in the mapping.

          Use serialized XML documents when configuring Configuration

          When building the configuration 40-60% of the time is used by the XML parsers and Dom4j to read up the XML document. Significant performance increases can be done by serializing the Document object's to disc once, and afterwards just add them to the configuration by deserializing them first.

          In the current cvs we have an experimental Configuration.addCachableFile() method that can be used as inspiration for previous Hibernate versions.

          public Configuration addCachableFile(String xmlFile) throws MappingException {        
                  try {
                      File file = new File(xmlFile);
                      File lazyfile = new File(xmlFile + ".bin");
                      org.dom4j.Document doc = null; 
                      List errors = new ArrayList();
                      if(file.exists() && lazyfile.exists() && file.lastModified()<lazyfile.lastModified()) {
                          log.info("Mapping lazy file: " + lazyfile.getPath());
                          ObjectInputStream oip = null;
                          oip = new ObjectInputStream(new FileInputStream(lazyfile));
                          doc = (org.dom4j.Document) oip.readObject();
                          oip.close(); 
                      } else {
                          doc = xmlHelper.createSAXReader(xmlFile, errors, entityResolver).read( file );
                          log.info("Writing lazy file to " + lazyfile);
                          ObjectOutputStream oup = new ObjectOutputStream(new FileOutputStream(lazyfile));
                          oup.writeObject(doc);
                          oup.flush();
                          oup.close();
                      }
                      
                      if ( errors.size()!=0 ) throw new MappingException( "invalid mapping", (Throwable) errors.get(0) );
                      add(doc);
                      return this;
                  }
                  catch (Exception e) {
                      log.error("Could not configure datastore from file: " + xmlFile, e);
                      throw new MappingException(e);
                  }
              }
          

          Disable Hibernates usage of cglib reflection optimizer

          Put the following line in hibernate.properties:

          hibernate.cglib.use_reflection_optimizer=false
          

          It will make Hibernate start faster since it does not try to build cglib-enhanced objects to access getter/setters.

          Note: It will have in impact on overall runtime performance since Hibernate will be forced to use standard JDK reflection for access. So it is most useful during development. (You will also get better error messages in some situations when the optimizer is disabled ;)


          ? NEW?COMMENT

          Serializing the Configuration object
          04 May 2004, 12:37
          luish
          Another approach would be to serialize the whole Configuration 
          object. What do you think about this? I have submitted a patch to  
          the Jira to make the Configuration Serializable (see bugs 492 and 
          147).
          ?
          addLazyFile() not there.
          06 Jul 2004, 11:50
          gstamp
          I can't fine addLazyFile() in CVS.  Is it still supposed to be there?
          ?
          Hibernate3 feature
          31 Aug 2004, 11:13
          gavin
          Try the Hibernate3 module (or just the alpha release)
          ?
          Information update?
          30 Mar 2005, 07:54
          gruberc
          The information on this page does not seem to be correct any
          more. With Hibernate 3.0rc1, there is no Configuration.addLazyFile()
          any more, but addCacheableFile(). How should it be used?
          ?
          lazy
          06 Mar 2006, 05:09
          steckemetz
          If you have terrible problems with startup time and
          do NOT need certain features like:
          
          * proxy objects
          * lazy loading
          
          or if you are using the stateless session,
          then you can disable lazyness on class level like:
          
          <class name="myClass" table="myTable" lazy="false">
          
          The default is true and forces byte code generation of
          some proxy class which takes a lot of time.
          Perhaps some hibernate guru can tell us, which other
          features will be disabled by this.
          ?
          I solve it.
          02 Aug 2006, 00:12
          cm4ever
          The Hibernate Configuration module implement is very bad.
          I write a module to realize the dynamic loading mapping files.
          But other function I can't resolve...
          
          Hibernate Dynamic Module
          This project is only a module of Hibernate http://www.hibernate.org Read
          mapping file until insert/update/delete/select the persistent class in
          Hibernate.
          http://sourceforge.net/projects/hbn-dyn-mod/
          posted on 2006-10-30 17:22 R.Zeus 閱讀(883) 評論(0)  編輯  收藏 所屬分類: HibernateJ2SE
          主站蜘蛛池模板: 新平| 屏南县| 寿宁县| 富民县| 乐山市| 公安县| 弥渡县| 东宁县| 宝山区| 平阴县| 大悟县| 巩义市| 淅川县| 黄浦区| 宣城市| 贵溪市| 安新县| 阿克苏市| 枞阳县| 磴口县| 航空| 息烽县| 松原市| 五峰| 中方县| 张北县| 荆州市| 丰台区| 淮滨县| 两当县| 河北区| 江口县| 观塘区| 涞水县| 哈尔滨市| 莱州市| 涡阳县| 烟台市| 台州市| 启东市| 抚宁县|