Avoid hogging & stuck threads in WLS when you call Web Services


If your app server has lots of threads waiting for response from a ws endpoint that doesn’t run as well as you would like you should start thinking in some kind of timeout control implementation.

If your are using OSB this configuration can be done in the PS settings, but if your integration in point to point tell your developers/partners to implement timeout this way:

Class1Service class1Service = new Class1Service();

        x = class1Service.getClass1Port();

        setWSTimeout(x, 30000); // esperamos 30 segundos

       x.getCosa(); // si mi servicio no responde en 30 segundos habrá una excepción que poder atrapar

 

    public void setWSTimeout(Object o, int timeout){

        Map<String, Object> context = ((BindingProvider)o).getRequestContext();

        //Set timeout params

        context.put(“com.sun.xml.internal.ws.connect.timeout”, CONST_CONNECT_TIMEOUT);

        context.put(“com.sun.xml.internal.ws.request.timeout”, timeout);

        context.put(“com.sun.xml.ws.request.timeout”, timeout);

        context.put(“com.sun.xml.ws.connect.timeout”, CONST_CONNECT_TIMEOUT);

    }

When timeout is reached you can catch the exception avoiding stucks:

javax.xml.ws.WebServiceException: java.net.SocketTimeoutException: Read time out after 30000 millis

          at com.sun.xml.ws.transport.http.client.HttpClientTransport.readResponseCodeAndMessage(HttpClientTransport.java:210)

          at com.sun.xml.ws.transport.http.client.HttpTransportPipe.createResponsePacket(HttpTransportPipe.java:241)

          at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:232)

          at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:145)

          at com.sun.xml.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:110)

          at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136)

          at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050)

          at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019)

          at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877)

          at com.sun.xml.ws.client.Stub.process(Stub.java:463)

          at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:191)

          at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:108)

          at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:92)

          at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:161)

          at com.sun.proxy.$Proxy200.getCosa(Unknown Source)

Enjoy 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.