File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Transferring large objects - J2EE design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transferring large objects - J2EE design" Watch "Transferring large objects - J2EE design" New topic

Transferring large objects - J2EE design

Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
Hello together,
I need a design suggestion for a 3 tier application:
The application has 3 tiers:
Presentation tier : JSP/ Servlets
Business tier: Session beans implement business logic
and access data from Data tier
Data tier: Legacy systems / DBs
Presentation and Business tiers run in different
weblogic servers (different Unix boxes as well). They
communicate using t3s protocol.
End-user uploads a huge file (upto 40 MB) using
webbrowser. (This is a mndatory requirement)
The uploaded file must be passed from presentation
tier to Business tier.
What would be the ideal design ?
1. Servlets read the file content and creates a java
object and passes it as a parameter to the remote
interface of session bean.
[ Disadv: memory problem. WHat happens if several
files are sent in a short ? ]
2. Servlet reads the uploaded file stores the data in
a DB. The key(s) to database record(s) is passed to
Session bean. Session bean reads the data from
[disadvantage: Since our design DB cannot be at
presentation tier. So servlet has to write several
records to Database (using JDBC). hence performance
problems ?]
3. Same as point 2. But instead of JDBC, records are
sent as messages to JMS server in Business tier. MDB
to recieve messages and write to DB and call local
business methods of session beans.
Any alternative ideas ? Please send in your ideas.
Srikanth Shenoy
Ranch Hand

Joined: Jan 24, 2004
Posts: 184
Hi Sankar,
Several factors drive your design choice.
1) What is the bandwidth between two machines hosting client and business tier?
2) Is bandwidth really a concern? Transferring a FileInputStream handle to business tier takes less bandwidth than Java objects.
3) But then again you are using Session Beans for business tier. Reading a file in EJBs is not guaranteed to work right and is not J2EE standard (although WebLogic support this without a hitch)
4)Is there a lot of business logic involved in construction of Java objects from the file? (This drives whether you should construct the Java objects on your Servlet side)
5)Finally since the file is large (40 MB), you are going to fall short of memory and CPU if you get a lot of hits - no matter where you process the request. With synchronous pricessing, you will also drastically affect the response time for higher loads. You must consider processing the request asynchronously with a scheduler (using a queueing mechanism - to process one request at a time) and inform the user that the request is being processed. Keepiong a long running transaction active is a sheer waste of web server/weblogic threads and other resources.
With all these considerations in mind, I think the best approach is to store the file from the Servlets and then signal the Session EJB to persist a request in a database about the pending request. Then have a scheduler process requests one (or two) at a time, by reading the file and doing the processing. You might notice a couple of non-standard J2EE in the solution above. That's how real world is after all... right ?
Let me know what you think.
[ February 21, 2004: Message edited by: Srikanth Shenoy ]

Srikanth Shenoy
Author of Struts Survival Guide : Basics to Best Practices
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
Thanks a lot for your input. But i am not sure about passing the FileInputStream to Session beans.
In my case, Presentation tier and Business tier are in two different machines and separated by network (Presentation tier is in DMZ and Business tier is in secure area behind firewall).
A multipart servlet recieves the uploaded file and stores in local server (Presentation tier). How do i pass this as FileInpustream object to a Business tier running in a different machine ?
FYI.. I am using Weblogic as Application server.
Thanks in advance for your clarifications
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
Few additional points about my application:
1. I am not doing any processing on the file recieved apart from adding a header record.
2. The Buisness tier passes this file further to an application (legacy system) via MQ.
I agree. Here's the link:
subject: Transferring large objects - J2EE design
It's not a secret anymore!