Configuration with a servlet
Installing Proxool in your web application
Configuration. You can configure Proxool using a Servlet too. There are three
ways:
1. XML file. Delegates to
JAXPConfigurator passing
in the filename. If the filename is not absolute then it is prepended
with the application directory.
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>xmlFile</param-name>
<param-value>WEB-INF/proxool.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
2. Property file. Delegates to
PropertyConfigurator
passing in the filename. If the filename is not absolute then it is prepended
with the application directory.
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>propertyFile</param-name>
<param-value>WEB-INF/proxool.properties</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
3. Init parameters. Delegates to
PropertyConfigurator
by passing in a new Properties object based on the servlet's init
parameters.
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>jdbc-0.proxool.alias</param-name>
<param-value>test</param-value>
</init-param>
<init-param>
<param-name>jdbc-0.proxool.driver-url</param-name>
<param-value>jdbc:hsqldb:.</param-value>
</init-param>
<init-param>
<param-name>jdbc-0.proxool.driver-class</param-name>
<param-value>org.hsqldb.jdbcDriver</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
The ServletConfigurator also shuts down Proxool by removing all connection pools. If you want
to disable this behaviour then use:
<servlet>
<servlet-name>ServletConfigurator</servlet-name>
<servlet-class>org.logicalcobwebs.proxool.configuration.ServletConfigurator</servlet-class>
<init-param>
<param-name>autoShutdown</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
If you run more than one web application in your servlet environment then you should consider
where you install the Proxool JAR. There are two options:
1. In the web application's lib directory (WEB-INF/lib). This has the following consequences:
Proxool pools will not be shared across web applications.
When you reload (or restart) your web application then a new
instance of Proxool is started. Unless you explicitly shutdown the old one then it will continue running
and continue to use resources (both locally and on the database). You can shutdown the pool by
either using the ServletConfigurator, above, or calling
ProxoolFacade.shutdown.
2. In the servlet container's common lib directory or elsewhere on the classpath. This has the
following consequences:
You can share common pools between web applications.
When you reload your web application the pool keeps running. The only way
to restart the pool is to either start and stop your servlet container or two explicitly shut it down and re-configure
it.
|