Is there a way to speed up loading an Embedded EJB container?

I am building my first Java EE web application using glass chip and netbeans. When I create a unit test that requires an embedded EJB container, it may take about 30 seconds to load. I thought this was understandable because it "mimics" a glass fish server. But then I came across this article from Adam Bien, which says:

The whole test, loading the container, takes my car in about 5 seconds.

http://www.adam-bien.com/roller/abien/entry/embedding_ejb_3_1_container

Therefore, I must assume that something is not configured correctly. I am running Linux Mint 12, my project uses a MySQL database, and my computer uses a dual-core 2 GHz, 4 GB RAM. Most settings use the default settings from the netbeans installation. (I ordered a new processor that will move the Benchmark CPU from 1700 to 7800 according to cpubenchmark.net).

What can I do to increase the loading speed of the Embedded EJB Container?

looking at the result, the main reason is:

org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA 

Here is the complete conclusion:

 Jan 9, 2012 5:01:57 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default. Jan 9, 2012 5:01:59 PM org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry Jan 9, 2012 5:02:00 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (1,476ms), startup services(2,053ms), total(3,529ms) Jan 9, 2012 5:02:00 PM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run INFO: JMXStartupService: JMXConnector system is disabled, skipping. Jan 9, 2012 5:02:02 PM org.glassfish.admin.mbeanserver.JMXStartupService shutdown INFO: JMXStartupService and JMXConnectors have been shut down. Jan 9, 2012 5:02:02 PM com.sun.enterprise.v3.server.AppServerStartup stop INFO: Shutdown procedure finished Jan 9, 2012 5:02:02 PM AppServerStartup run INFO: [Thread[GlassFish Kernel Main Thread,5,main]] exiting Jan 9, 2012 5:02:02 PM org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry Jan 9, 2012 5:02:02 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (5,874ms), startup services(150ms), total(6,024ms) Jan 9, 2012 5:02:02 PM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run INFO: JMXStartupService: JMXConnector system is disabled, skipping. Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.EJBContainerProviderImpl skipJar INFO: ... skipping entry with a Manifest file with a special attribute: glassfish-embedded-static-shell.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding EJB module to ScatteredArchive classes Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive mysql-connector-java-5.1.13-bin.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive commons-codec-1.6.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive commons-codec-1.6-bin.zip Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive ant.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive primefaces-3.0.RC2.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive ant-junit.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive log4j-1.2.15.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive classes Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive junit-4.8.2.jar Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.EJBContainerImpl deploy INFO: [EJBContainerImpl] Deploying app: org.glassfish.embeddable.archive.ScatteredArchive@1ebafda6 Jan 9, 2012 5:02:08 PM org.hibernate.validator.util.Version <clinit> INFO: Hibernate Validator 4.1.0.Final Jan 9, 2012 5:02:09 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle <init> INFO: SEC1002: Security Manager is OFF. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle onInitialization INFO: SEC1010: Entering Security Startup Service Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.PolicyLoader loadPolicy INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created. Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle onInitialization INFO: SEC1011: Security Service(s) Started Successfully Jan 9, 2012 5:02:17 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. Jan 9, 2012 5:02:26 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver. Jan 9, 2012 5:02:26 PM org.eclipse.persistence.session.file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU INFO: EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504 Jan 9, 2012 5:02:29 PM org.eclipse.persistence.session.file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU INFO: file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU login successful ... 

thanks

+6
source share
2 answers

You can try another instance of EJBContainer.

Testing time for OpenEJB Embedded EJBContainer is in the range of 1 second. It supports GlassFish descriptors - we use them instead of our own when we run the Java EE TCK, because we are too lazy to write the several thousand descriptors we need, and the TCK already comes with full GlassFish descriptors.

Alternatively, perhaps try a different approach completely.

For a more unit test style, perhaps check this out: fooobar.com/questions/905559 / ... That is, create the application in a test case and throw some mockery if necessary.

+2
source

Here is what I have done so far, and my test cycle is up to 13.

1) Upgraded my processors. I switched from one dual-core 2 GHz to two quad-core 2.5 GHz, which shaved off for about 5 s.

2) Manually set up the assembly files, frankly, I do not quite understand why he made such a difference, but shaved off for almost 10 seconds. http://netbeans.org/kb/docs/javaee/javaee-entapp-junit.html#Exercise_1d

 Map<String, Object> properties = new HashMap<String, Object>(); // Use the MODULES property to specify the set of modules to be initialized, // in this case a java.io.File properties.put(EJBContainer.MODULES, new File("build/jar")); 

3) The persistence.xml file has been changed to NOT create database tables. I just have to get it back when I make changes to the structure of the entity.

But the numbers are a little messy and forgive me if I'm not going to waste time on the right statistical analysis. When I turn on the "create" table in persistence and return to basic auto-configuration, it starts in 16 seconds. But before the processors appeared, I was up to 18 years old. Thus, the numbers do not quite add up.

I was also very pleased to receive an offer from Adam Bien. I asked him if he was ready to write an article on this topic. He said that he was covered in detail in this article and can be found in more detail in his book and in another article:

+1
source

Source: https://habr.com/ru/post/905556/


All Articles