The first connection to Glassfish v3 is slow

When trying to connect to Glassfish v3 from a swing application, it is very slow for the first time. It takes 4-10 seconds. On the client side:

public void myMethod(){ NewSessionBeanRemote facade; try { InitialContext ic = new InitialContext(); facade = (NewSessionBeanRemote) ic.lookup(NewSessionBeanRemote.class.getName()); target.setText(facade.businessMethod()); } catch (NamingException ex) { ex.printStackTrace(); } } 

On the server side:

 @Stateless public class NewSessionBean implements NewSessionBeanRemote { @Override public String businessMethod() { return String.valueOf(Math.random() + 121 + 300); } } @Remote public interface NewSessionBeanRemote { String businessMethod(); } 

What do I need to change in the environment?

+4
source share
2 answers

When trying to connect to Glassfish v3 from a swing application, it is very slow for the first time.

Perhaps due to lazy initialization of Application Server services (EJB Container, connection pool, ...).

It takes 4-10 seconds.

What about subsequent calls?

0
source

This is how Java EE works. When the page is called for the first time, all JSP files are compiled and all beans are created. Even if you turn off lazy initialization, you will have to wait the same amount of time at startup.

Quote from wikipedia.org https://en.wikipedia.org/wiki/JavaServer_Pages#Compiler

The JavaServer Pages Compiler is a program that parses JSPs and converts them into executable Java servlets. This type of program is usually embedded in the application server and starts automatically when you first access the JSP, but the pages can also be precompiled for better performance or compiled as part of the build process to check for errors.

If you want, you can try precompiling everything and see if it works better:

http://www.avajava.com/tutorials/lessons/how-do-i-precompile-my-jsps.html

0
source

All Articles