Documentation and Books

Recent site activity

When using alot of GWT.create() calls the application performance is very slow, how to solve this?

Very simple, minimize the usage of GWT.create(), this can be done by using the following pattern for for example message resources:

  public interface GeneralConstants extends Constants {

    public final static GeneralConstants instance =
     (GeneralConstants)GWT.create(GeneralConstants.class);

    String ok();
  
    String cancel();

    ...

  }

Now when you use the interface in the following way:

  public void someMethod() {
    setText(GeneralConstants.instance.ok());
  

This will ensure that the GWT.create is only executed once for that interface.

For RPC classes you can do the same, suppose you have the PersonService interface and the async version of the interface PersonServiceAsync. Then also create a implemented version of the Async interface that will do the GWT.create for you:

  public class PersonServiceAsyncImpl implements PersonServiceAsync {

    public static PersonServiceAsync instance =
     (PersonServiceAsync)GWT.create(PersonService.class);

  

    /**
     * Make the constructor private so it is not possible to create an instance.
     */
    private PersonServiceAsyncImpl() {
    }

    public void getPersonDetails(Integer id, AsyncCallback callback) {
      instance.getPersonDetails(id, callback);
    }
  }

In this way you will only have one GWT.create per RPC interface. This will really help improve the performance of making RPC calls (let alone the memory consumption).