• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem showing BLOB images in Multi-threaded model  RSS feed

 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the following code, I'm retriving BLOB image from OracleXE database and sending the image to the browser. The table is OracleXE's COUNTRIES table (HR Schema) with BLOB gif images added. The browser displays all those images (flags) in a table.

My problem is, when I use SingleThreadedModel, it works perfectly. But in Multi threaded model, most of the time some of the images get missing.

I'm new to Java/JSP comming from VB background. Please help me to solve this problem. Thanks in advance!

The project contains 3 files:
ShowImages.java - retrives BLOB image from DB.
Countries.java - generates HTML table rows.
StreamCopyTool.java - uti9lity to direct stream copy.
index.jsp

ShowImages.class is mapped in "/myapp"

ShowImages.java
===================



Countries.java
==================



StreamCopyTool.java
-------------------



index.jsp
----------



Edit: After I edited this post, the teread title got truncated !! :0

[ August 08, 2007: Message edited by: Piash Chaudhuri ]
[ August 09, 2007: Message edited by: Bear Bibeault ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet instance variables are not thread safe. This means that the value or state gets shared between all requests coming through. Therefore the following is unsafe:

 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding to what David has said ,SingleThreadModel is deprecated and the class variable might be the cause of the problem.Avoid using class scoped variables to prevent corruption issues.

You can configure a datasource with the container that you are using for hosting/testing and request the datasouce as and when you need a database connection.
 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Superb!!!

Just as you said, I removed the Statement variable, and the problem is gone!
I kept the Connection variable though - to speed up the servlet. Is there any better idea ?


Also, could you guys please point me some good tutorial on JDBC+Oracle ?

(I'm VERY new to Java. But have prior programming experience in VB. I've finished reading Just Java 2 and Servlet part of Core Servlets book. I need to do 2 projects in Servlet/JSP+Oracle for my degree, a Shopping portal and a Car Finance website.)

Any tutorial that might help me on this ?

And, thanks again for solving this problem.
[ August 09, 2007: Message edited by: Piash Chaudhuri ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Piash Chaudhuri:

I kept the Connection variable though - to speed up the servlet. Is there any better idea ?


Yes, look into container managed connection pooling.
 
Tony McClay
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Piash Chaudhuri:

I kept the Connection variable though - to speed up the servlet. Is there any better idea ?



Always glad to see success stories. Just Java 2 and Servlet part of Core Servlets book are great books. May I also suggest you take a look at the J2EE Tutorial from sun. It is free, my favorite word! http://java.sun.com/javaee/5/docs/tutorial/doc/

May I also suggest you take a look at Java Persistence Architecture (JPA). It is a Plain Old Java Object development paradigm (With Annotations) for Database Access. It is part of J2SE and J2EE and the reference implementation is based on Oracle Essentials. I am a fan of this specification, and I know has helped me significantly delivering database solutions faster.

Also, Java Server Faces is a new interesting technology. For Delivering JSP Functionality. I believe it is the way for new development. JSF along with a tool set called Struts from the Apache Jakarta umbrella uses a Model View
Controller (Design Pattern) infrastructure for JSP Development. I prefer these modes of development because it separates logical responsibilities.

Please weigh the learning curve on both of these and others. You may ask your professor if these tools are applicable for the items he is trying to teach. Many years ago we in the industry coded JDBC directly, and Servlets/ JSP's directly. I think we have matured a bit past this low level of development for efficiency and code structure and others. We will continue to evolve.

Good luck! Looks like you are on your way to a fantastic career!


Cheers.

Tony
Sun Certified Web Business Component Developer
Sun Certified Web Components Developer for J2EE
Sun Certified Programmer for the Java 2 Platform
 
Piash Chaudhuri
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Tony! I'll read the Sun J2EE tutoral.

As I've mentioned before, I have 4+ years of learning/working experience in VB6. After so many years of developing on M$ platform, I'm finding it very hard to change technology. The most dificult problem is, ironically, so many choices!!! And I always need to google when I see a new acronym like POJO/JINI etc.

Currently I'm in my final semester. For our projects we were free to choose our language/platform. I wanted to move forward from VB6.

My first preference was, oviously, C#, but our course has JSP. Not dotNet.
As I had to learn Java/JSP for my course, and don't have much time to learn two languages simultaniously, I choose Java.

My project proposals already got approved. I don't think they will allow me to use JSF. But, thanks for your suggesation, I've already planned to learn JSF and Ajax after I finish this project.
[ August 09, 2007: Message edited by: Piash Chaudhuri ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the record.
Not everyone here is a fan of JSF/Struts.

A lot of companies are moving away from large, bloated frameworks that try to abstract basic web development.
[ August 09, 2007: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!