[jboss-user] [EJB 3.0] - How to deal with huge uploaded file in JBoss

jochen.reinhardt do-not-reply at jboss.com
Wed May 13 07:50:24 EDT 2009


Hi folks,

I'm writing a medium-scale application for one of our customers, using JBoss 5.02, JSF, tomahawk and EJB3 with a MySQL database. I need to do a file import - one big file - through the web interface (JSF file upload) and handle the file contents in EJB stateless sessions. The problem is that the size of the file is thus huge, that when I process it, I receive OutOfMemoryExceptions.

My approach is to handle the import asynchronously - as it may take several hours. So I use JMS to send a message for asynchronous processing. 
First, I tried to generate a JMS-Message with all the data inside. But that's not feasable for the life system. I also did not like that the file content was saved to the database - as part of JMS transaction handling. I also assume that the file content was kept in memory several times - by JSF, by JMS and may be by EJB stateless session bean.

My second approach was to store the uploaded file in a temporary file and just pass in the file path with the message. When receiving the the message I just need to load the file from disk again in the JMS MessageListener. But this fails - my test file is > 100MB - reading it into a byte array caused OutOfMemoryException. I'm also not sure, if this already violates the EJB spec. Is accessing files allowed from within JMS-Message Listeners and / or EJB session beans? Or is that some restriction related to clustered setups?

My preferred way would be to open an InputStream to the file and pass that in to a Stateless Session Bean local method call. That should be possible - as the input stream is passed by reference for local calls. But I'm not sure if that is supported in JBoss.

Please advise!

Jochen





View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4230799#4230799

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4230799



More information about the jboss-user mailing list