Reputation: 1765
I have a Jax-WS service that needs to call out to another JAX-WS service with a CXF client. Because this client requires additional WS-* features, such as WS-Trust, I create a new CXF bus.
private void startupBus()
{
// if the bus is already active, shut it down to pick up any endpoint changes
if (bus != null) {
bus.shutdown(false);
}
bus = BusFactory.newInstance().createBus();
// Add logging interceptors to log messages to and from the services it calls
...
inBusLog.setPrettyLogging(true);
outBusLog.setPrettyLogging(true);
bus.getInInterceptors().add(inBusLog);
bus.getOutInterceptors().add(outBusLog);
bus.getInFaultInterceptors().add(inBusLog);
bus.getOutFaultInterceptors().add(outBusLog);
BusFactory.setThreadDefaultBus(bus);
...//create service proxy with this bus, setup STS client parameters, etc
}
Both my bus and my service proxy are static instances, and because I want to modify my parameters externally, this method re-runs once per day.
I'm seeing a memory leak, however, when this service stays up and running for a few days. Its relatively slow, so I cannot pinpoint if its something to do with my bus/proxy rotation logic, or if its elsewhere.
Is there any additional cleanup that needs to be done on the proxy( such as a java.io.Closable.close
? ) or am I incorrectly configuring/managing my CXF bus instance?
Upvotes: 1
Views: 1691
Reputation: 953
Maybe it will be useful for the future https://docs.jboss.org/author/display/JBWS/Apache+CXF+integration#ApacheCXFintegration-BusselectionstrategiesforJAXWSclients
try {
Service service = Service.create(wsdlURL, serviceQName);
MyEndpoint port = service.getPort(MyEndpoint.class);
//...
} finally {
BusFactory.setThreadDefaultBus(null);
// OR (if you don't need the bus and the client anymore)
Bus bus = BusFactory.getThreadDefaultBus(false);
bus.shutdown(true);
}
Upvotes: 3