On Wednesday 24 September 2008 4:10:14 am MattJax wrote: > I have a servlet-based application which uses CXF as a client to call a > remote web service. > > I am using the following code to create my webservice object within the > servlet code: > > <snippet> > JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); > factory.setServiceClass(WebServiceInterface.class); > factory.setAddress(wsConfig.getWSDLUrl()); > webService = (WebServiceInterface) factory.create(); > </snippet> > > I then call methods (usually just one) on the webService object, and then > the servlet thread completes normally and I do not do anything explicitly > to close this webService object. > > My question is: should I be closing this webService object explicitly? It > this tying up resources?
The service object it self will get garbage collected and anything it uses will go away. However, the above will create a Bus object that won't be released. The Bus is the registry for all the plugins and stuff. However, creating the bus is expensive so it's definitely not something you want to do each time if you can avoid it so holding onto that is probably OK. If you need/want to kill that as well, you can call BusFactory.getDefaultBus().shutdown(true); > Also, is the JaxWsProxyFactoryBean thread safe? I.e. could I have an > initialised JaxWsProxyFactoryBean object as a static member of the servlet > I am using? No. The factorybeans are not reusable. Once they have "created" their proxy they should be discarded. -- Daniel Kulp [EMAIL PROTECTED] http://www.dankulp.com/blog
