tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vijay Kandy <>
Subject RE: Sharing an object between servlets
Date Fri, 04 Oct 2002 15:09:11 GMT
The number of coordinates is huge - in thousands so cant put them in the

I have attempted your second idea. And yes I go to the DB for each request.
The problem with the Singleton is, I donno who should start the class. If
the HTML servlet starts the Singleton, will the object still be accessible
to the image servlet?

Thank you,

 -----Original Message-----
From: 	Shapira, Yoav [] 
Sent:	Friday, October 04, 2002 9:42 AM
To:	Tomcat Users List
Subject:	RE: Sharing an object between servlets

 << File: ATT196478.txt >> << File: ATT196479.txt >> Hi,
There are many ways you can do this.  Here are two examples:

1. Since the HTML servlet embeds the URL of the PNG servlet, why not put
the coordinates in the URL?  E.g. have the HTML servlet output
<img src="myPngServlet?x1=0&x2=1"> and then the PNG servlet does
String x1 = request.getParameter("x1");
and so forth.

2. Do you really go to the DB for each request?  It may be better (at
least for performance, but also addressing this sharing thing) to have a
singleton responsible for getting coordinates from the DB.  The servlets
ask the singleton for the coordinates, which gets them.  If the
singleton doesn't have them, it goes to the DB and caches the results.
So that the second time those coordinates are requested, it's a simple
and quick hash lookup (or whatever kind of lookup suits you) to get
them.  This way you can also pre-cache frequently requested coordinates,
and do all sorts of stuff to improve performance... But more importantly
it keeps a nicer degree of decoupling between the two servlets.

I hope this helps,

Yoav Shapira
Millennium ChemInformatics

>-----Original Message-----
>From: Vijay Kandy []
>Sent: Friday, October 04, 2002 10:28 AM
>To: 'Tomcat Users List'
>Subject: Sharing an object between servlets
>Dear All,
>We are building a map tool - to draw maps and show some data on them.
>have this situation. I have a servlet that gets coordinates from the
>database and draws the map on its OutputStream (the content type is set
>png image). There is another servlet (content type is text/html) that
>the URL of the first servlet. This servlet also gets coordinates from
>database, and populates them over the image so I can do some image map
>mouseOver() tricks using javascript. I was wondering if there was a way
>make just one call to the database and share the coordinates between
>servlets. Right now, I will try any thing!
>Thank you,
>To unsubscribe, e-mail:   <mailto:tomcat-user-
>For additional commands, e-mail: <mailto:tomcat-user-

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message