JBoss 6EAP on OpenShift, too many active sessions
long_hdi May 27, 2013 2:52 AMI am using JSF 2 on JBoss 6 EAP. I made a sample application which used JSF as the View, EJB for logic and JPA for Persistence. The bean in JSF has RequestScoped. EJB is stateless.
This is index.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:h="http://java.sun.com/jsf/html"
   xmlns:c="http://java.sun.com/jsp/jstl/core">
   <h:head>
   <title>Long HDi</title>
   </h:head>
   <h:body>
   <c:forEach var="tweet" items="#{tweets.getAll}">
   <p>
  #{tweet.content}<br />
   </p>
   </c:forEach>
   </h:body>
</html>
JSF Bean:
@Named("tweets")
@RequestScoped
public class Tweets implements Serializable {
   @EJB
   private TweetServiceLocal tweetService;
   private List<Tweet> tweets;
   public List<Tweet> getGetAll() {
   return tweetService.findAllSortedByTimeDesc();
   }
}
EJB:
@Stateless
public class TweetService implements TweetServiceLocal {
   @PersistenceContext(unitName = "LongHDi-ejbPU")
   private EntityManager em;
   @Override
   public Tweet create(final String content, final Date postTime) throws ContentTooLargeException {
   if (content.length() > 480)
   throw new ContentTooLargeException("Content must have less than 480 charaters!");
   else {
   try {
   Tweet tweet = new Tweet();
  tweet.setContent(content);
  tweet.setPostTime(postTime);
  em.persist(tweet);
   return tweet;
   } catch (Exception e) {
   return null;
   }
   }
   }
   @Override
   public java.util.List<Tweet> findAllSortedByTimeDesc() {
   return em.createNamedQuery("Tweet.findAllSortedByTimeDesc").getResultList();
   }
}
When I sent a few hundred requests to it, the JBoss 6 server threw this exception:
JBWEB000065: HTTP Status 500 - JBWEB000209: Session creation failed due to too many active sessions
JBWEB000309: type JBWEB000066: Exception report
JBWEB000068: message JBWEB000209: Session creation failed due to too many active sessions
JBWEB000069: description JBWEB000145: The server encountered an internal error that prevented it from fulfilling this request.
JBWEB000070: exception
javax.servlet.ServletException: JBWEB000209: Session creation failed due to too many active sessions
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
JBWEB000071: root cause
java.lang.IllegalStateException: JBWEB000209: Session creation failed due to too many active sessions
  org.apache.catalina.session.StandardManager.createSession(StandardManager.java:297)
  org.apache.catalina.connector.Request.doGetSession(Request.java:2651)
  org.apache.catalina.connector.Request.getSession(Request.java:2357)
  org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:790)
  com.sun.faces.context.ExternalContextImpl.getSession(ExternalContextImpl.java:157)
  com.sun.faces.application.view.FaceletViewHandlingStrategy.getSession(FaceletViewHandlingStrategy.java:494)
  com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:400)
  com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:124)
  javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286)
  com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
  com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
My question is: why did the server create so many sessions? I used RequestScope and Stateless bean, how come they end up in sessions? What can I do to overcome this situation? If I use only servlet and JSP, when there are too many requests, the server is slowed down but at least it is not halted like this.
 
    