When to NOT use a database connection pool in Java?

I can find many questions about how to use the connection pool and why it is a good idea, but I am wondering if this is really necessary.

I am creating a server application and although it is multithreaded, I was careful that only one thread ever accessed my database connection.

So, does it make sense to use a connection pool?

Can't I just open a connection to my database at the beginning of the life cycle and use this one connection forever, or will it be a timeout if it has been inactive for too long?

I really should call close()in my connection after something to do with him, or just call close()on ResultSetand / or Statement?

+4
source share
3 answers

What is a database connection? This is a session with your database and as such:

  • Session state of client and server sides
  • There is a transaction associated with this session.

Now, since your client application is multithreaded, I suspect that there are only a very limited number of cases where your setup makes sense, namely:

  • You are not using session state, even inadvertently (and this may be provider specific)
  • You do not use transactions and always automatically execute
  • Even with automatic fixation, there may be race conditions, so you make sure that this does not happen.
  • , , .

/ , , , , . (, ..), . , ( ), - . , ?

:

, ?

(. ), .

-, ?

, . JDBC , - .

script script, script, Swing .. .

- close() , - , call() ResultSet / Statement?

close() , DataSource.getConnection() (, DataSource).

close() , .

+5

, , , . , .

- , , . , , , , .

, , , ; , , , "" . , .

, , , . , , ( ).

+1

, -, ?

, , .
, / .
, , - .
- .
​​ dao... , .
, .

0

Source: https://habr.com/ru/post/1664578/


All Articles