hezjing schrieb:

> I have many service creation (like the following code) in my GWT
> application,
> 
> XxxxServiceAsync xxxxService = GWT.create(XxxxrService.class);
> 
> 
> Is it safe to make all XxxxServiceAsync a singleton?

It's common practice. There are already IDEs that do that for you
automatically. In general you implement a Util-class that is holding
the system-wide Async-Instance:

Inside the Interface defining the remote service, in your
example above XxxxrService you put in the following:

/**
 * Utility class for simplifying access to the instance of async service.
 */
public static class Util {
    private static XxxxrServiceAsync instance;

    /**
     * Returns the system-wide instance of the endpoint allowing access
     * to the XxxxrService of the server
     * @return The instance
     */
    public static XxxxrServiceAsync getInstance() {
        if (instance == null) {
            instance = (XxxxrServiceAsync) GWT.create(XxxxrService.class);
            ServiceDefTarget target = (ServiceDefTarget) instance;
            target.setServiceEntryPoint(GWT.getModuleBaseURL() + 
"XxxxrService");
        }
        return instance;
    }
}

So calling a RPC can be done with
XxxxrService.Util.getInstance.myRemoteFunction(param, callback);

This can be seen as "Best practice" (to refer to another thread
in this group ;-)


Regards, Lothar


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to