Using winsw (GitHub) https://github.com/kohsuke/winsw )It is very convenient to convert Java application into windows service and deploy it on Windows Server.
Detailed operation steps can be searched, the document is relatively rich.
Here’s a problem I had. After I have configured every step according to the documentation, there is no problem with the service installation. Then when I start, the service throws an exception “error 1067: unexpected process termination”
public class App
{
public static void main( String[] args ) throws IOException, InterruptedException {
Logger logger = LogUtil.getLogger();
logger.info("a");
logger.severe(new Date().toString());
}
}
The reason is that the main method of Java module is not blocking. When the service is started, winsw will execute the Java – jar command in the configuration file to start a process, and record the process ID of the process, and then there will be a series of operations. The main method here is not blocking. Java jar starts the process, and winsw remembers the process ID. however, when the process information is used later, it is found that the process has terminated, so an exception is thrown.
Solution: the process should be a blocking process, that is, the process cannot end. The following code is OK.
public static void main( String[] args ) throws IOException, InterruptedException {
Logger logger = LogUtil.getLogger();
logger.info("a");
logger.severe(new Date().toString());
while (true) {
logger.info("a");
logger.severe(new Date().toString());
Thread.sleep(10000);
}
}
Note that blocking doesn’t work System.in.read (), because in a non command line environment, this line of code will not have any running results.
Springboot application itself is a blocking application, so when using winsw tool to create windows service for springboot, this problem will not occur.
Read More:
- Java retainAll throws an unsupported operation exception record
- Realize the simplest recursive call, simulate exception in thread “main” java.lang.stackoverflowerror exception
- Windows Java application startup batch script
- Java uses ZipFile to decompress the zip file and runs normally under Windows. Linux reports an error
- Resolve the problem of “event ID 4107” or “event ID 11” errors recorded in the application logs of windows and windows server
- Apache2 cannot be started and an error is reported for apache2.service failed because the control process exited with error code.
- No converter found capable of converting from type [java.lang.String] to type [java.util.Map<java.la
- The solution of a Java exception has occurred. And error exception in thread when eclipse runs
- python: This application failed to stat could not find or load the Qt platform plugin “windows”
- This application failed to start because it could not find or load the Qt platform plugin “windows”.
- About WLW (Windows Live Writer): “unable to connect to your log service: invalid server response” solution
- Job for docker.service failed because the control process exited with error code. See systemctl sta
- RuntimeError:An attempt has been made to start a new process before the……
- PHP in Windows combined with bat batch processing to achieve multi process verification proxy server function
- The @ Autowired annotation in springboot is invalid in ordinary classes. How to solve and use the null pointer exception java.lang.nullpointerexception
- nt service 1072 No need to restart, repeat the method of installing the service program or service driver
- Job for network.service Failed because the control process exited with error code. See “SystemC
- Java – how to shuffle an ArrayList
- Solution to the flash back, error report and unexpected exit of idea MAC windows
- How To Fix Windows Java Error 1723