Possibly [OT], and just disregard if so.

I am just trying to follow this thread and to understand, from my very superficial and elementary knowledge of things Java and Tomcat.

So we have a Tomcat, which somehow has a "pool of database connections" ready to be lent to webapps.

And we have a webapp capable of borrowing one of the connections from the pool to do something with it, the understanding being that when it's done, it gives it back to the pool.

And we have several Tomcat threads ready to execute instances of this webapp, to service HTTP requests.

We also have a client, who sends 3 HTTP requests in a row to Tomcat, as follows :

- Client sends HTTP request # 1 to Tomcat
- Tomcat passes this request to a thread, which runs the webapp
- the thread borrows a connection from the pool
- the thread for the moment doesn't do anything with it, but sends a response to the Client
- request # 1 is terminated, the thread is ready to process another request
- Client receives response to request # 1
- Client issues HTTP request # 2, which is a db transaction
- Tomcat receives the request # 2, and passes it to the same / a different thread. Say it is the same (how that works I don't know, question below). - the thread somehow re-uses the same db connection which was borrowed before. How ? was it saved somewhere and can this thread get the same one back ? But suppose it does.
- the thread makes the db query, and sends a response to the Client
- request # 2 is terminated, the thread is ready to process another request
- Client receives response to request # 2
- Client issues HTTP request # 3, which is a signal for the webapp to return the db connection to the pool - Tomcat receives the request # 3, and passes it to the same / a different thread. Say it is the same (how that works I don't know). - the thread somehow re-uses the same db connection it had borrowed before, to finalise the db transaction, then returns the connection to the pool. The thread sends a response to the Client.
- request # 3 is terminated, the thread is ready to process another request
- Client receives response to request # 3 and is happy.

Now my question is : considering this is HTTP, where each request is supposedly independent from previous and following ones, can a scheme like the above possibly work ? Is it one particular thread which holds this borrowed db connection, and is request # 2 necessarily processed by the same thread as request # 1 ?
Where is the borrowed connection stored between the requests ?

Am I right in thinking that for such a scheme to work, even with well-behaved clients, the borrowed db connection would need to be saved somewhere independent of a Tomcat thread, but dependent on some kind of client "session", so that any thread could pick it up where another one or itself left it between transactions of that same client ?

Is that what everyone is trying to say ?





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to