cxf動的呼び出しwebservice設定タイムアウト、テストスレッドセキュリティ


import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

public class WSClient {
	public static void main(String[] args)throws Exception {
		String wsdlUrl = "http://172.16.11.11:8080/webws/CalculatorPort?wsdl";
		// 
		JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
		final Client client = factory.createClient(wsdlUrl);

		// 
		HTTPConduit http = (HTTPConduit) client.getConduit();      
		HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();      
		httpClientPolicy.setConnectionTimeout(3000);  //     
		httpClientPolicy.setAllowChunking(false);    //  
		httpClientPolicy.setReceiveTimeout(3000);     // 
		http.setClient(httpClientPolicy);
		
		// client , 
		ThreadPoolExecutor pool = new ThreadPoolExecutor(5,50,1000,
				TimeUnit.MICROSECONDS,new ArrayBlockingQueue(50));
		for (int i=0;i<100;i++){
			pool.execute(new Runnable() {
				@Override
				public void run() {
					try {
						String threadName = Thread.currentThread().getName();
						int a = new Random().nextInt(10);
						int b = new Random().nextInt(10);
						Object[] res = client.invoke("adD", a,b);
						System.out.println(threadName+":"+a+"+"+b+"="+res[0]);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}
	}
}

結果:
pool-1-thread-37:0+5=5
pool-1-thread-21:1+4=5
pool-1-thread-33:6+3=9
pool-1-thread-49:6+0=6
pool-1-thread-42:7+1=8
...
...
...
pool-1-thread-7:7+5=12
pool-1-thread-46:9+2=11
pool-1-thread-17:6+2=8
pool-1-thread-34:2+3=5
pool-1-thread-36:8+3=11
pool-1-thread-40:1+9=10
pool-1-thread-26:4+4=8
pool-1-thread-35:3+4=7