I guess I will answer my own question
Hopefully it helps others attempting to do the same thing.
Here is how I have now defined my spring beans (this actually works):
Code:
<bean id="xboxService" class="com.scranthdaddy.xbox.service.XboxServiceImpl">
<property name="webServiceTemplate" ref="webServiceTemplate"/>
</bean>
<bean id="messageSender" class="org.springframework.ws.transport.http.CommonsHttpMessageSender">
<property name="connectionTimeout" value="15000"/>
<property name="readTimeout" value="60000"/>
<property name="maxTotalConnections" value="20"/>
<property name="maxConnectionsPerHost">
<props>
<prop key="*">20</prop>
</props>
</property>
</bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<property name="defaultUri" value="http://xbox2.scranthdaddy.com"/>
<property name="messageSender" ref="messageSender"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
My first question: Is calling the xboxService thread-safe and can I call the xboxService concurrently? The answer is yes, because by default the CommonsHttpMessageSender uses HttpClient's MultiThreadedHttpConnectionManager. Just be sure to set the messageSender properties per your requirements.
My next question: How I do call the xboxService concurrently? The answer was (for my use case) to use some java util concurrent classes:
Main.java
Code:
package com.scranthdaddy;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) throws Exception {
Main main = new Main();
main.runBatchThreads();
}
private void runBatchThreads() {
// initialize list of WebServiceTask objects
List<WebServiceTask> webServiceTasks = new ArrayList<WebServiceTask>();
for (int i = 0; i < 5000; i++) {
WebServiceTask webServiceTask = new WebServiceTask();
webServiceTasks.add(webServiceTask);
}
System.out.println("Starting threads");
// create ExecutorService to manage threads
ExecutorService executorService = Executors.newFixedThreadPool(20);
for (WebServiceTask webServiceTask : webServiceTasks) {
// start thread
executorService.execute(webServiceTask);
}
// shutdown worker threads when complete
executorService.shutdown();
System.out.println("Threads started, main ended");
}
}
WebServiceTask.java
Code:
package com.scranthdaddy;
public class WebServiceTask implements Runnable {
public void run() {
// call xboxService ...
}
}
This is really cool because if you use jconsole, you can see the 20 threads started up. And then when then threads are all done they get shutdown. Nice job by the Sun/Oracle developers!