1

Our team at work chose to develop web services using all the tools that NetBeans 7.1.2 provides.

Unfortunately, our web services are too unstable and a lot of times offline. It's something we can't solve now. Our decision was to implement a timeout in our clients. But we didn't find any option or documentation about it.

Is there a way to make clients throw an exception when the service takes, for example, 5 seconds to return an answer? So we can't catch this exception and treat the view's flow.

I'm asking because there are ways to implement it with threads and time counters but it's obvious that other programmers had gotten already the same issue.

By the way, we're using JAX-WS.

Thanks a lot.

2
  • Are you saying if a user waits for 5 seconds, your service is under heavy load, so you want to return a 503 error? Nov 9, 2012 at 19:13
  • No. Actually our managed beans consume web service clients to update some panels. But these panels can't interfere in the page flow. So, I want to set the panel "rendered" property to false if the web service takes more than 5 seconds to return an answer. Nov 9, 2012 at 19:16

2 Answers 2

2

Use java.util.concurrent package classes. For example, you can execute Future instance with timeout: future.get(5, TimeUnit.SECONDS), and if it excepts with TimeoutException, you can react as you want:

Future<String> future = executor.submit(new Callable<String>() {
    public String call() {
        return webService.executeServiceMethod();
    }
});
try {
    String result = future.get(5, TimeUnit.SECONDS);
    processResult(result);
} catch (TimeoutException ex) {
    displayMessageToUserOrExecuteAgain();
}
5
  • That may well work, but the call is going to continue to run, consume resources, etc. Your call may time out but the underlying artifact won't. Nov 9, 2012 at 19:40
  • @hoaz, it worked and I'm in one step of closing the question. But only one thing keeps me worried. Is it dangerous of memory leaks on application servers? I'm asking because I'm afraid of working with non-managed threads and with Future I can't kill the thread if a TimeoutException is thrown, right? Nov 9, 2012 at 19:54
  • future#cancel will work fine, actually there are other ways to free resources, like shutting down the executor itself, so you can experiment with it
    – hoaz
    Nov 9, 2012 at 21:43
  • @Adriano 'Stanley': Also refer to stackoverflow.com/questions/2148915/…. This seems to solve your problem in a much more elegant manner. Apr 3, 2013 at 12:29
  • Hi need help, I have configured the connection timeout for injected client, but its taking the default time more that 1 mins. Can anyone advise something ?
    – JDGuide
    Oct 26, 2015 at 6:33
0

Web services clients can be configured with timeouts, refer this https://community.jboss.org/thread/156015 How do I set the jax-ws client request timeout programatically on jboss?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.