Building a commercial-quality Web application in Java
A small company explains what it learned while developing <br> software to support Netscape's AppFoundry program
By Rich Kadel, JavaWorld.com, 10/04/96
Page 2 of 4
Executing the server
The database server application should be running constantly -- like an HTTP server, for example -- but this kind of operation
usually requires that system files be modified to start the application at boot-up. And if the application dies unexpectedly,
it typically requires intervention by the system administrator. This seemed like too much hassle for such a simple application,
so we took a different approach:
- First, the applet would attempt to connect to the database server, assuming the server was already running.
- If the server was not already running, the applet would attempt to load a CGI program on the server, using a Java URL and
the openStream function to cause the program to be executed.
- The CGI program would set up the environment and then execute the server.
- The applet would then attempt to connect to the server, trying once per second until some maximum number of attempts is reached.
(The connection usually succeeds within one attempt.)
One trick to this was that the CGI program had to finish executing, or the URL connection in the browser would not complete
and the application would hang. The solution for Unix was to start the Java database server application in a background process.
No problem.
Enter Windows NT
We had another requirement. We had to support server solutions for both Unix (initially Solaris) and Windows NT. The biggest
hurdle related to the NT port that we had to overcome was in "backgrounding" the database process. With Unix, we took for
granted the fact that background processes and foreground processes are handled identically by the operating system. Windows
NT, however, does not treat background processes as "first class citizens." There are no tools for backgrounding a process.
No simple shell symbols, or function calls. We dug out the Advanced Windows textbooks and put together a small program (included
with the Org Chart distribution) that takes a command line with arguments and executes that command in a new process "without
a console" (that is, in the background).
It worked, but still had the downside that there are no tools included with the standard Windows NT distribution to locate
and/or kill the process if necessary. The Windows NT Resource Kit (sold separately) supplies some Unix equivalents to "ps"
to find the process, and "kill" to terminate it. Not nearly as good as their Unix counterparts, but they do the job. Third-party
vendors also supply Unix commands and shells for NT. Rebooting the system also works. :-)
The CGI program also had to be rewritten for NT. In fact, we never could get Netscape Enterprise Server to execute a ".CGI"
file using the PERL.EXE program. And Perl is not as portable as some people claim. Many of the functions that I had used in
the Unix version (including "fork" and "exec" of course) simply were not implemented in the Win32 version. That's one of the
reasons I believe Java still has a good chance to replace Perl as the language of choice for CGI programming (not to mention
the fact that Perl script is completely incomprehensible).