Recently, I don't know what's going on. The program on the server suddenly goes wrong. Some pages cannot be accessed normally, or only half of them are displayed. I have encountered this problem before, it should be because a problem occurs when reading data, and it is said that such a release still has some potential risks.
At the beginning, for the convenience of users, I directly registered Tomcat as a Windows service and set the Startup Type to "auto start", so that even if the user restarts the Server due to power failure or other reasons, the program can also start automatically without manual start. It was not until today that this problem was exposed that I realized a big problem: when the program starts, it needs to connect to the database, but the database service often starts slowly. Therefore, before the database service is fully started, if the application service has been started, an error may occur.
Google has spent half a day using the following solutions:
Java code
- SC config tomcatapp depend = oracleserviceopb/oracleserviceorcl
sc config tomcatAPP depend= OracleServiceOPB/OracleServiceORCL
That is to say, the Tomcat service is set to depend on the two database services. That is, Tomcat is started only after the two database instances are started.
Note that the service name "atatapp" is not displayed in the service list. The name is not accurate:
Here, we need to write "service name" instead of "display name". Or, the simplest is to go to the Registry HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services to see the real service name. In addition, the SC command format should also be noted that "depend =" is an overall command parameter, followed by a space, and then followed by the dependent service name, multiple services are separated by commas (,). The service name is not enclosed in quotation marks.
After this command is completed, we can see that the dependency between the Tomcat service and the Oracle service is indeed established:
However, the problem persists after the restart !! Google again. Wait until the problem is solved ~~
To sum up all the steps, we hope that the experts will give you some advice:
1. Open cmd.
2. Go to the tomcat_home/bin directory.
3. Enter the command "service install tomcatapp" to install the service. The command to uninstall the service is: "service reomve tomcatapp"
. 4. Set the service to auto start and enter the command "SC config tomcatapp start = auto ".
5. Set the service dependency and enter the command: "SC config tomcatapp depend = oracleserviceopb/oracleserviceorcl"
6. Restart the machine to see if it works.