Search code examples
javajakarta-eejpadb2eclipselink

JPA in Java SE vs Java EE performance


I'm using JPA/Eclipselink in Java SE (Oracle Java 7) and Java EE (Websphere Liberty) environments.

I have a component which is called from both Java SE and Java EE (by component I mean the same source code), which executes JPA queries. (the Java SE run is started with -javaagent:lib/eclipselink.jar param)

I have conducted 3 test runs:

  1. in Java EE - the code runs fast (e.g. queries take around 0.01 seconds)
  2. in Java SE - the code runs slow (2 seconds/query)
  3. in Java SE AND Java EE server is running - the code runs as fast as in the first case

I'm a bit puzzled; why does starting up a Java EE server causes code (running in a different JVM) to speed up? And what can I do to speed up the queries in Java SE without running a Java EE server?

UPDATE

This issue might be related to the underlying database. I run the applications in the following order

  1. started Java SE app - queries are slow
  2. started Java EE app - queries in Java SE app are fast
  3. stopped Java EE app - queries are still fast in Java SE app

So, there might be some kind of database cache(?) which the Java EE app initializes, but the Java SE app doesn't - however I don't see anything in the log what might be related to this.

One more thins I saw, is that the two apps use a different database driver (which might cause some performance difference, but wouldn't explain why starting both apps would cause the speed up ...)


Solution

  • Finally, I figured it out:

    • in JEE enviroment JPA used connection pooling automatically; but in JSE enviroment, no connection pooling was available
    • when a connection to any db2 database created, a number of agents are started (e.g. monitoring, collection statistics, etc.); to start (and terminate) these agents it took about 2 seconds (these agents were visible in db2 get snapshot on all for database output)
    • when JEE was running, a persistent (pooled) connection was maintained to the db2 scema; this way all agents were running
    • when the J2SE app was started with the agents running, the overhead of creating a database connection was very small; on the other hand if no persistent connection was available this overhead was small

    Got the queries (connections) speed up by using C3PO.