H
H
have_a_questions2016-04-16 18:07:36
Java
have_a_questions, 2016-04-16 18:07:36

How is the connection to the database organized in a multi-threaded java servlet environment?

Each time a request is made to the servlet, a new thread is created for the client. If a connection to the database is made in the servlet, then for each client a new connection will be created, that is, for each thread, a separate connection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kornachev, 2016-04-16
@have_a_questions

In theory, connections to the database should already be created in advance. There is such a thing as Connection Pool - a set of already open connections. When the servlet needed to access the database, a connection is taken from this pool, and the servlet works with it, and as soon as the servlet no longer needs the base, it must release the connection (return it to the pool). If there are a lot of requests, and there are not enough connections, then the servlet suspends work until a free connection appears in the pool. It's in a nutshell.
You can read a short article or search online.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question