Please see my code example of a JAX-WS Webservice:
@WebService
public class ClassA {
@WebMethod
public synchronized void doSomething() {
new Thread(new Runnable() { // Thread X
@Override
public void run() {
synchronized (ClassA.this) {
// Do something which should be run in this separate
// thread, but not twice at the same time
try {
System.out.println("Thread X Start");
Thread.sleep(10000);
System.out.println("Thread X End");
} catch (InterruptedException e) {
}
}
}
}).start();
}
}
If the WebMethod is called twice, the second call is waiting for thread X to complete - why?