I’m doing my first Java EE web application using glassfish and netbeans. When I create a unit test that requires the embedded EJB Container it can take around 30s to load. I thought that was completely understandable since it’s “mimicking” the glassfish server.
But then I came across this article from Adam Bien where it says:
The entire test, with booting the container, takes on my machine about
5 seconds.
http://www.adam-bien.com/roller/abien/entry/embedding_ejb_3_1_container
So I have to assume something is not configured right. I’m running Linux Mint 12, my project is using a MySQL database and my PC is 2Ghz dual core, 4 GB ram. Most everything is using the default settings from the netbeans install. (I did order a new processor that will move the CPU Benchmark from 1700 to 7800 according to cpubenchmark.net)
What can I do to improve the speed of booting the Embedded EJB Container?
while looking at the output, the main culprate seems to be:
org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
Here is the full output:
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
You could try another EJBContainer impl.
The test time of the OpenEJB Embedded EJBContainer is in the 1 second range. It supports the GlassFish descriptors — we use them instead of our own when we run the Java EE TCK as we’re too lazy to write the several thousand descriptors we would need and the TCK already comes with complete GlassFish descriptors.
Alternatively, maybe try a different approach entirely.
For a more unit test style maybe check this out: https://stackoverflow.com/a/8716630/190816
I.e. build the app in the test case and throw in some mocking as needed.