title: Long Polling with Java and JBoss
body: <p>I'm looking for an example, how to implement a longpoling mechanism in java. I would love to use a stateless EJB.</p>
  
  <p>I know that something like that would work:</p>
  
  <pre><code>@WebService(serviceName="mywebservice")
  @Stateless
  public class MyWebService {
      @WebMethod
      public String longPoll() {
           short ct = 0;
           while(someCondition == false &amp;&amp; ct &lt; 60) {
               sleep(1000);  // 1 sec
               ct++;
           }
           if (someCondition)
               return "got value";
           else
               return "";
      }
  }
  </code></pre>
  
  <p>Unfortunately i know that this does'nt scale. Can i return in the webmethod without finishing the response and finish it somewhere else?</p>