Practically, I always wait for get connection a few minutes.
How did you measure that? And is the connection successfully returned after that time? Or does it fail to get the connection? Where is the DB server located?
Also, I see that you have this in your datasource configuration:
As per the docs:
validationQuery - SQL query that can be used by the pool to validate connections before they are returned to the application. If specified, this query MUST be an SQL SELECT statement that returns at least one row.
So it really depends on how many rows your test.testl table contains. If it has many rows, then it might affect the performance. You might want to change that query to perform better.
log.warn("After (DataSource)ctx.lookup"); //log datetime before connect
Connection conn = datasource.getConnection();//here is problem - I wait, wait, wait
log.warn("After datasource.getConnection()"); //log datetime after connect
After a few minutes the connection is successful. I don't have any fails.
DB server locate on the same network.
So it really depends on how many rows your test.testl table contains
This table (test.test1) contains just one row.
But is strange for me that
when I stop in browser then connection,
and after that I connect second time - I get the connection immediately.