Data Source & Connection Pool & JNDI

Through previous practice, we have successfully connected our application to the Database using JDBC. 

But allowing user and application to connect to DB directly would cause certain issues. 

1. Creating Connection to DB cost a lot of recources, and assume that the quantity of users are huge, it would very likely to cause the cache in the DB server to run out. 

                        

(Image downloaded from Web.) 

Solution for above issue. 

Using DataSource. and Connection Pool. 

Connection Pool would be responsible for managing our connection, and assign a free connection for user and application to use, 

And it will be released if the connection is no longer used. 

DataSource is fetched through JNDI (Java Name and Directory Interface. )

(Image downloaded from web.)

So to conclude the relationship could be summarized as below. 

JNDI --> DataSource --->  Connection --> Connection Pool. 

Code Example. 

猜你喜欢

转载自www.cnblogs.com/codingyangmao/p/10865154.html