Stateless session bean that multi threads?

D

davout

As a relative EJB newbie... as I undersatand it you're not supposed to
multi-thread inside the implementation of a stateless session bean method.
(Right?)

In this case how do I solve a situation where my stateless session bean
wants to draw data from 'n' sources and then consolidate and return the
results as one array?? Ideally you'd want to create a sub thread for each
different data source. Are here any workarounds?
 
J

John C. Bollinger

Do not crosspost. Followups directed to comp.lang.java.beans.
As a relative EJB newbie... as I undersatand it you're not supposed to
multi-thread inside the implementation of a stateless session bean method.
(Right?)

Right. Attempting to start new threads from within an EJB
implementation method would be a violation of the bean's contract with
its container.
In this case how do I solve a situation where my stateless session bean
wants to draw data from 'n' sources and then consolidate and return the
results as one array?? Ideally you'd want to create a sub thread for each
different data source. Are here any workarounds?

Whether a threaded scenario in fact makes much sense in the first place
rather depends on the number and nature of the data sources. If they
exhibit sufficiently low latency with respect to their number then very
little is to be gained by accessing them through multiple threads
instead of serially.

If there *is* an advantage to be gained then you probably want to look
at ways of performing the individual lookups asynchronously. The
standard tool for asynchronous tasks in the EJB world is the
message-driven bean. There may be other alternatives available based on
the specific characteristics of your data sources.

The final alternative is to push the multi-threaded access out to the
client side. That's actually the simplest, and if the client is local
then perhaps also the best performing. You could write a client-side
wrapper that makes it transparent to users.


John Bollinger
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,930
Messages
2,570,072
Members
46,522
Latest member
Mad-Ram

Latest Threads

Top