Long polling with Java and JBoss

I am looking for an example how to implement longpoling mechanism in java. I would love to use stateless EJB.

I know something like this will work:

@WebService(serviceName="mywebservice")
@Stateless
public class MyWebService {
    @WebMethod
    public String longPoll() {
         short ct = 0;
         while(someCondition == false && ct < 60) {
             sleep(1000);  // 1 sec
             ct++;
         }
         if (someCondition)
             return "got value";
         else
             return "";
    }
}

Unfortunately, I know that this does not make scale. Can I return to the web method without completing the answer and end it somewhere else?

+3
source share
2 answers

, , . -/ , , 10 -, " ", - , "". , , ( ). , "push-" .

:

  • - HTTP- () 5 , , "someCondition",
  • AFAIK, Tomcat ( JBoss ) "" , Thread.sleep()
  • -, Servlet API 3, HTTP-
  • : - (push-)
+2

JAX-WS Web- , . :

+3

Source: https://habr.com/ru/post/1770710/


All Articles