title: JAX WS multiple requests management
body: <p>I'm starting studying java web services with JAX WS. The first chapter of the book I'm reading shows how to build and deploy a simple jax ws web service using only java SE. In particular, the web service is published through the Endpoint class. After publishing the web service, the author specifies that "Out of the box, the Endpoint publisher handles one client request at a
  time ... if the processing of a given request should hang, then
  all other client requests are effectively blocked. An example at the end
  of this chapter shows how Endpoint can handle requests concurrently
  so that one hung request does not block the others."</p>
  
  <p>To see this, I tried to send two requests to a web service with 2 threads. Here is the code:</p>
  
  <pre><code>@WebService(endpointInterface = "ProveVelociJava.WS.MyWsWithJavaSE.SayHello")
  public class SayHelloImpl implements SayHello {
      public String greetings(String param) {
          System.out.println("\nStarting " + param + "...\n");    
          if(param.equals("miao")) {      
              try {           
                  Thread.sleep(9000);
              }
              catch(Exception e) {}
          }
          System.out.println("Ended " + param + "\n\n");
          return "Hi, " + param;
      }
  }
  
  public class SayHelloPublisher {
      public static void main(String[ ] args) {   
          // 1st argument is the publication URL
          // 2nd argument is an SIB instance
          Endpoint.publish("http://127.0.0.1:9899/say", new SayHelloImpl());
      }
  }
  
  class MyClient extends Thread {
      private static URL url;
      private static QName qname;
      private static Service service;
      private static SayHello eif;
  
      static {
          try {
              url = new URL("http://127.0.0.1:9899/say?wsdl");
              qname = new QName("http://MyWsWithJavaSE.WS.ProveVelociJava/", "SayHelloImplService");
              service = Service.create(MyClient.url, MyClient.qname);
              // Extract the endpoint interface, the service "port".
              eif = service.getPort(SayHello.class);
          }
          catch(Exception e) {}
      }
      private String name;
      public MyClient(String n) {
          name = n;
      }
      public void run() {
          System.out.println(MyClient.eif.greetings(this.name));
      }
      public static void main(String args[ ]) throws Exception {  
          MyClient t1 = new MyClient("miao");
          MyClient t2 = new MyClient("bau");
          t1.start();
          t2.start();
      }
  }
  </code></pre>
  
  <p>If I start MyClient class, the thread called "miao" sends its request and then goes to sleep. However, the thread called "bau" does not wait for the previous thread and its request is immediately satisfied.</p>
  
  <p>Am I missing something? Can java threads be used to simulate multiple requests?</p>
  
  <p>Thanks a lot for your help,
  Nico.</p>