Is the method

public void messageReceived(final IoSession session, final Object message) throws Exception {

threadsafe per IoSession?

That is can the same IoSession under any circumstance receive messages at the same time?


If it is threadsafe, then i am curious if this should work for accessing EM in a threadsafe way?

And if it is assured to close? And/or under what circumstances sessionDestroyed might not be called?

ie OutOfMemoryError, etc

   public void sessionCreated(final IoSession session) throws Exception {
session.setAttribute("EM", entityManagerFactory.createEntityManager());

   public void sessionDestroyed(final IoSession session) throws Exception {
final EntityManager entityManager = (EntityManager) session.getAttribute("EM");
       entityManager.close();

public void messageReceived(final IoSession session, final Object message) throws Exception { final EntityManager entityManager = (EntityManager) session.getAttribute("EM");
       // do something with EM

I am also wondering, bar Spring, etc, thoughts on whether this would be considered a good practice?

Assuming the above plays out.

Thanks,

Jason

Reply via email to