Dan,
On 8/12/25 10:52 PM, Daniel Schwartz wrote:
If you go to my website, www.worldholidaysandevents.com, and make a
request for holiday info for, say, Tallahassee, Florida, USA, 2025,
you will see the following actions:
1. The Countries list is filled with a list of countries. This is one DB
connection.
2. When you select United States of America, the States and Cities lists
are filled with US states and cities. This is one more DB connection, actually
two queries in one connection.
Great. Any time you know you must perform multiple db-related actions,
you should definitely do them with a single connection all at once.
3. When you select Florida from the States list, then the cities list is
refilled with just Florida cities. This is one more DB connection.
Yes and no. "When you select" implies that there is user interaction.
For a web application, "user interaction" means "request is made from
client (browser) to server (your application running in
Glassfish/Tomcat)". From the perspective of your code, each of (1), (2),
and (3) is a single connection in a single request. When you click
"Florida" on your page, you are not repeating queries (1) and (2) again
before proceeding to (3). Only (3) is performed, and only requires a
single connection to do so.
If you *are* repeating (1) and (2) before (3), you might consider
whether or not it's necessary to do so.
4. When you select 2025 as the year and click “Explore” this is another DB
connection, calculating dates and returning the list of holidays and events.
I'm assuming that this operation gets a connection, gets all necessary
data, then returns the connection. After that it does whatever other
preparation is necessary to return the response to the client, and then
the request-response workflow is complete. This should also only take
one connection.
Everything you described above should be possible with a single
connection in the pool. If your pool grows in development with only you
making serial requests, then "something else" is going on.
So the way the system currently operates, all these DB connections are
necessary. However, if there were some way to identify a user “session”, then
all of these queries could be carried out in one session and with only one DB
connection per session. Probably there is a way to do this, but I haven’t
explored it yet. Right now, if you run these operations, you’ll see that the
response is very quick. However, I don’t know what might happen if I were to
get a lot of users.
Assuming that "session" above means "HttpSession" then definitely do not
do this. You want a connection to be out of the pool for as short a time
as possible.
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org