Looking up local ejb in custom thread..

Discussions

EJB programming & troubleshooting: Looking up local ejb in custom thread..

  1. Looking up local ejb in custom thread.. (2 messages)

    Hello, We use Websphere 6.0. I have a web project and an ejb project. when looking up a local ejb stub in the web project everything works fine. but if I try to lookup a local ejb stub in a thread that is created at the startup of a servlet I get a : "Name comp/env/ejb not found in context "java:"." , NameNotFoundException. When I create a Thread in the init() method of a servlet, within that thread's code I'm still in the web container/JVM, right ? or has it the same effect as if I'd code in a standalone java application ? if the latter is true, would it be appropriate to create a stub in the init() method of the servlet and pass it to the thread after its creation ? I mean is it ok to cache a local ejb reference / stub ? if not what would be a workaround to the NameNotFoundException ? Thanks in advance.
  2. When you create your own thread, the security context and other contexts (thread local resources) are not automatically copied to the new thread. Therefore, the approach you are trying is simply not possible using WAS without writing a lot of work around code to help you out. Simply try to avoid creating custom threads if it means that you need access to the server's resources, or treat them strictly as "remote clients". /N
  3. Simply try to avoid creating custom threads if it means that you need access to the server's resources, or treat them strictly as "remote clients".
    Very aptly put in words by Nick. But if Nick's method is not feasible, do the lookup part in servlet thread and pass the reference to the custom thread. I believe this may work (I have never tried this myself though)