while going through interview questions i came across this question .
Can a database connection pool be instantiated in init
method of servlet instead of server connection pool?
What will be the problem?
It is true that connection pool can be instantiated in init
method of Servlet and is available for the web application
to use, but generally there can be many web application
required to use database connection pool, and multiple
web applications do not have access beyond ServletContext.
So it is desirable to have external resources defined at
server level, not at an application level.
Please let me know what does rhe author mean by this ??
Save India From Corruption - Anna Hazare.
posted 7 years ago
Lets say you have 5 application that needs to acces a particular database say MY_DB.
Now if you configure the connection pool for this database in the server then it is available for all the application that uses this connection pool else you have to individually initialize the connection pool for each and every application that uses the same database.
You know ServletConext is per application and generally you will duplicate the same logic in each and every application for instantiating the connection pool and hence it is better to define the external resources in the server level(Web/Application Server).
SCJP 6,SCWCD 5,SCBCD 5
Failure is not an option.
Fire me boy! Cool, soothing, shameless self promotion:
the new thread boost feature brings a LOT of attention to your favorite threads