Threading in EJBs


EJB programming & troubleshooting: Threading in EJBs

  1. Threading in EJBs (7 messages)

     I read in the "Mastering EJBs" book that the EJB spec does not allow multithreading inside the EJBs. But I tried to make an EJB by implementing Runnable and starting a thread inside the Bean class. But neither javac nor ejbc gave any errors. Shouldn't atleast ejbc give me a warning. I'm using Weblogic 8.1.3 and my compiler is jrockit-jdk.
    Also what is the behaviour if there is any non-final static variable in EJBs.

    Threaded Messages (7)

  2. Threading in EJBs[ Go to top ]

    (1) I dont think "does not allow" is right - All those things like "Do not do IO inside EJBs", "Do not multi-thread" etc., are best practices in using EJBs. Of course, it does not tie your hands to prevent you from doing that - but it is never a good practice. You might have the reason why in the book, I believe.

    (2) Not clear what your question on variable is - you can of course use non final statics.

  3. Threading in EJBs[ Go to top ]

    Thanks for the reply. In (2) I was asking that if we do have a non-final static variable in stateless/statefull session beans and its value is changed within the bean, then when the same EJB object is used to service some other request, doesn't it provide a wrong value ( the one that was set in last request).
  4. Threading in EJBs[ Go to top ]

    If you have a stateless SB, then you shouldn't have any non static variable because the same bean instance can be used to serve other clients.
    If you have a statefull SB, you shouldn't have any problem. That bean instance will only serve one client (unless of course you share that bean instance with other clients, but I don't think you'd do that)
  5. sorry[ Go to top ]

    I missunderstand you. My answer was for non-static variables.
  6. Threading in EJBs[ Go to top ]


    I got it now - Yes. Statics are a NO NO too. They dont mean anything actually in a cluster of EJBs :-).

  7. Thanks[ Go to top ]

    Thanks for the help
  8. Threading in EJBs[ Go to top ]

    You can do whatever you want. But in J2EE it is safer and better to follow best practices