Finding Large Prime Numbers
This example illustrates two capabilities of Java servlets:
- The ability of servlets to maintain persistent state.
In this case, the servlet starts a low-priority thread to calculate prime
numbers, and returns a page showing initial results. Whenever the client
asks for an update, it returns the new results. It also maintains a set
of the 30 most recently calculated results, to return immediately if a client
asks for something already computed.
- The ability of servlets to manipulate HTTP response headers.
In this case, it sends
Refresh
headers if the prime calculations
are not yet complete, along with a page showing the intermediate
results.
This page is part of my
Tutorial on Servlets and JSP. © 1999
Marty Hall. All
source code freely available for unrestricted use. Created for for
work in the Research
and Technology Development Center of the Johns Hopkins University
Applied Physics Lab, for courses in the Johns Hopkins Part-Time MS
Program in Computer Science, and for various industry seminars and
on-site Java short courses.