java - How to set timeout value for a @WebMethod in a @Stateless bean? -
i trying figure out if possible set timeout value web method in @stateless bean. or if possible. have searched quite bit , found nil related question.
example:
@webservice @stateless public class test { @webmethod @webresult(name = "hello") public string sayhello(){ homecoming "hello world"; } } thanks lot in advance answers.
so after searching , learning little bit have solved problem doing following: in case have created stateless bean contains @asynchronous method:
@asynchronous public future<string> sayhelloasync() { //do time consuming ... homecoming new asyncresult<string>("hello world"); } in sec bean exposing method web services have done following: @webservice @stateless public class test { @ejb firstbean myfirstbean;//first bean containing async method. /** * can used in futher methods follow * running web service method */ private future<string> myasyncresult; @webmethod @webresult(name = "hello") public string sayhello(@webparam(name = "timeout_in_seconds") long timeout) { myasyncresult = myfirstbean.sayhelloasync(); string myresult = "service still running"; if(timeout>0) { seek { myresult= myasyncresult.get(timeout, timeunit.seconds); } grab (interruptedexception e) { myresult="interruptedexception occured"; } grab (executionexception e) { myresult="executionexception occured"; } grab (timeoutexception e) { myresult="the timeout value "+timeout+" reached."+ " service still running."; } } homecoming myresult; } } if timeout set, client wait amount of time until reached. process still has run in case. hope help others. emmanuel java java-ee timeout stateless
No comments:
Post a Comment