Java Reference
In-Depth Information
and then closing the connection. This type of algorithm, although simple, is very time consum-
ing. Opening and closing a database connection with every request is hardly an optimal solu-
Now, take a look at this servlet in action. Open your browser to the following link:
Your results should look similar to Figure 7.11. Try this several times so you can get used to
the speed.
F IGURE 7.11
TitleListServlet output.
To speed up the servicing of requests, you could open the connection to the database in the
init() method and then close it in the destroy() method, but you would be limited to a sin-
gle connection. If you chose to do this, you would need to have your servlet implement the
SingleThreadModel interface. This interface defines a single-thread model for servlet execu-
tion, guaranteeing that no two threads will execute concurrently the service() method of the
implementing servlet. This would save execution time, but would limit you to servicing
requests one at a time.
Search WWH ::

Custom Search