views:

156

answers:

1

Hi,

I have a session bean that uses Bean managed txns. This bean has one business method that simply delegates the control to a POJO which takes care of all the processing. Here this POJO starts and closes transactions (UserTransaction).

Now the question is can I span new threads in the POJO so that I can create a new thread when I need to service 40 or 50 tasks at a time.

I am using EJB2.1 on J2EE 1.4.

Please advice.

Regards.

+1  A: 

If I understood correctly, there is no need for threading your pojo.

Your container is naturally threaded. The different requests that are send to the container each have a thread alloted for them.

Inside an allotated thread, the calling sequence goes from your session bean to your pojo, the threads are still in use. Your pojo is already being called in a multi-threaded way.


Actually, what you need to do is ensure that your Pojo code is multi-threadable (but not spawn any thread).

  1. Either your pojo instance is multi-threadable, that is:

    • no fields
    • ...
  2. Otherwise, if your pojo instance is not multi-threadable, you only need to create a new Pojo instance for each call, and everything will work fine.

KLE