i wasn't sure about this either, but i also use the Stub._setProperty() to
specify a user-name to the WSS4J handler so
i couldn't have multiple threads using the same stub instance anyway so i
wrapped it into a ThreadLocal and added it
to my client-side util class:
public class ClientUtils {
/** holds the FreezerAPI object for the calling thread */
private static final ThreadLocal m_threadsFreezer = new ThreadLocal();
public static FreezerAPI getFreezerApi() throws MalformedURLException,
ServiceException {
FreezerAPI freezerApi = (FreezerAPI)m_threadsFreezer.get();
if (freezerApi == null) {
FreezerWebServiceLocator locator = new FreezerWebServiceLocator();
if (m_freezerUrl == null) {
m_freezerUrl = new URL(locator.getFreezerWSAddress());
}
freezerApi = locator.getFreezerWS(m_freezerUrl);
m_threadsFreezer.set(freezerApi);
}
return freezerApi;
}
public static FreezerAPI getFreezerApi(String loginName) throws
MalformedURLException, ServiceException {
FreezerAPI api = getFreezerApi();
setLoginName(api, loginName);
return api;
}
public static void setLoginName(FreezerAPI api, String loginName) {
((Stub)api)._setProperty(WSHandlerConstants.USER,
loginName);
((Stub)api)._setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, new
UserIdPWCallback());
}
}
that seemed to reach a good balance between performance (i.e., not having to
create lots of stubs) and thread-safety.
HTH.
................ron.
> As said in subject -
> Is WSDL2Java generated client stub meant to be used as thread-safe shared
> service by multiple threads simultaneously, or is it meant to be
> instantiated for each call ?
>
> -Vjeran
>
>