The HTTP async client requires a separate thread pool for it to work.   
Creating that thread pool and such is quite expensive and is thus managed by 
the Bus so that it can be shared by multiple clients and if you create/dispose 
many client objects quickly, that expense isn’t incurred.   In your case, you 
aren’t explicitely shutting down the Bus.   If you grab the bus 
(BusFactory.getDefaultBus()) prior to creating the clients and then calling 
bus.shutdown() at the end, that SHOULD cause the pools to shutdown and any 
other resources cleaned up.

Note: some of the other transports like JMS that would keep a persistent 
connection to the broker would also require some cleanup.

That all said, I’d need to check with the HTTPClient folks.  It MAY be possible 
for us to configure it to use daemon threads instead.   Not really sure though. 

Dan


On Jan 21, 2014, at 12:02 PM, Jose María Zaragoza <[email protected]> wrote:

> Hi
> 
> 2014/1/20 Jose María Zaragoza <[email protected]>:
>> Hello:
>> 
>> I'm using Apache CXF 2.7.8 and I've got a questions about asynchronous
>> invocation:
>> 
>> 
>> 1) When I use a standalone client with the next code :
>> 
>> //
>> Future<?> future = client.sendAsync(request, new EmailAsyncHandler());
>> 
>> while (!future.isDone())
>> {
>>     System.out.println("Waiting ...");
>> 
>> }
>> System.out.println("Done");
>> 
>> 
>> the JVM process never is finished although "Done" log is printed
>> 
>> About jvisualm , there is a thread running
>> 
>> java.lang.Thread.State: RUNNABLE
>> at sun.nio.ch.WindowsSelectorImpl$SubSelector.poll0(Native Method)
>> at 
>> sun.nio.ch.WindowsSelectorImpl$SubSelector.poll(WindowsSelectorImpl.java:273)
>> at 
>> sun.nio.ch.WindowsSelectorImpl$SubSelector.access$400(WindowsSelectorImpl.java:255)
>> at sun.nio.ch.WindowsSelectorImpl.doSelect(WindowsSelectorImpl.java:136)
>> at sun.nio.ch.SelectorImpl.lockAndDoSelect(SelectorImpl.java:69)
>> - locked <0x23f296c8> (a sun.nio.ch.Util$2)
>> - locked <0x23f296d8> (a java.util.Collections$UnmodifiableSet)
>> - locked <0x23f29650> (a sun.nio.ch.WindowsSelectorImpl)
>> at sun.nio.ch.SelectorImpl.select(SelectorImpl.java:80)
>> at 
>> org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:366)
>> at 
>> org.apache.cxf.transport.http.asyncclient.AsyncHTTPConduitFactory$1.run(AsyncHTTPConduitFactory.java:340)
>> at java.lang.Thread.run(Thread.java:662)
>> 
>> I know that I can do System.exit(0) , but I wonder why if Future
>> object is done , Thread is not finished. What is the reason ? How I
>> can finish this thread ? Could be a problem if asynchronous client is
>> executed in a web container ?
>> 
>> 
>> 
>> 2) I'm using @UseAsyncMethod annotation in synchronous method signature like
>> 
>> @UseAsyncMethod
>> public EmailResponse send(EmailRequest emailRequest)
>> 
>> but asynchronous implementation like
>> 
>> public Future<?> sendAsync(EmailRequest emailRequest,
>> AsyncHandler<EmailResponseWrapper> sendHandler)
>> 
>> is never invoked , did I forget something ?
>> 
>> I using cxf-rt-transports-http-hc module
>> 
>> 
>> Thanks and regards
> 
> 
> 
> Any suggestion/idea ?
> 
> Thanks

-- 
Daniel Kulp
[email protected] - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com

Reply via email to