This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Doing IO operations in a Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Doing IO operations in a Session Bean" Watch "Doing IO operations in a Session Bean" New topic
Author

Doing IO operations in a Session Bean

Savio River
Greenhorn

Joined: Feb 21, 2003
Posts: 3
Hi ,
Is it possible to do a getInputStream and getOuputStream of bytes in a Session Bean..
My Client is an Applet, I have a Servlet in between Applet and session bean, Now my session Beans does a lot of processing and I would like to get the status of its progress to the client, for this I have open a Stream from the Applet..
Do u think this is posible, pls let me know if there is another way..
Thanks
Savio
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Consider a callback Session bean. When you fire up the "workhorse", pass the callback SB in and have the workhorse post progress to it. Then you can have your applet periodically query the callback SB.
That being said, I don't recommend using EJBs as long-running process entities. You can't spawn threads in them, you shouldn't do I/O in them and HTTP clients won't operate the way you want, since the HTTP request isn't resolved until you return from both the bean and from any intermediary logic (e.g. servlet/JSP).
A more effective approach is to create an "engine" process(es) that runs under its own thread(s) and queue up requests that come in. You can use either standard JavaBeans or EJBs to track the work requests.


Customer surveys are for companies who didn't pay proper attention to begin with.
Savio River
Greenhorn

Joined: Feb 21, 2003
Posts: 3
Thanks Tim,
If I have to use a callback session bean , I will have to do a look up for each progress of the process which is quite an overhead....Am I right !!
A more effective approach which u had suggested to Queue up requests ....
But in my application my EJB Session Bean dispathches a lot of records to another process.. and it takes atleast 3 hrs so I have to send some sort of a Status to the client..
[ February 22, 2003: Message edited by: Savio River ]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16020
    
  20

Well, any process that takes 3 hours I would definitely not want to put in an EJB. I'm sure I could think of other reasons, given time, but a very good one would be that it could delay server shutdowns up to 3 hours - and EJB just isn't expected to be an interruptable process.
Something that long-running you wouldn't want to tie up the client's computer with a progress monitor anyhow. However they would appreciate a "dashboard" they could look at periodically. The dashboard could either query the process server directly via the callback bean technique I mentioned before. As to the overhead, it's mostly dependent on how often you want to query.
It's not uncommon for really long-running processes to spawn an e-mail notification when they're done. That way the user isn't sitting around waiting on things, but will find a notification whenever they are ready to deal with the results.
Savio River
Greenhorn

Joined: Feb 21, 2003
Posts: 3
Thanks Tim, thats a very satisfactory answer, I will be trying out something like that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doing IO operations in a Session Bean