简体   繁体   中英

First connect to Glassfish v3 is slow

When trying to connect to glassfish v3 from swing application it is very slow for the first time. 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?

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

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

A JavaServer Pages compiler is a program that parses JSPs, and transforms them into executable Java Servlets. A program of this type is usually embedded into the application server and run automatically the first time a JSP is accessed, but pages may also be precompiled for better performance, or compiled as a part of the build process to test for errors.

If you want, you can try to pre-compile everything and see if it works better:

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

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

Might be due to the lazy initialization of Application Server services (EJB Container, Connection pool,...).

Takes 4-10 seconds.

What about subsequent calls?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM