In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the relevant knowledge of "how to solve the problem that the Java process is missing". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. Tried by the operating system.
The following problems have been encountered by more than one partner: my java process is gone, there is nothing left, it just evaporates.
Why? Is it because you are too affectionate and have too many partners?
This is a very interesting and skillful question.
Execute the dmesg command and there's a good chance you'll see your process crash message lying there.
In order to see when it happened, we habitually add the parameter T
Dmesg-T
Obviously, the operating system doesn't like your process and gives it to Kill.
This phenomenon is related to the memory management of Linux.
Because the Linux system uses virtual memory allocation, the use of JVM code, library, stack and stack will consume memory, but the applied memory, as long as there is no real access, is not counted, because there is no real allocation of physical pages.
Use more and more memory as you use it. The first protective wall is SWAP;. When SWAP is almost used, it will try to release cache;. When both resources are exhausted, the killer appears. Oom killer will jump out when the system runs out of memory and selectively kill some processes in order to free up a little memory.
So at this time, our Java process is terminated "actively" by the operating system, and JVM doesn't even have a chance to make last words. This information can only be found in the operating system log.
To solve this problem, first of all, we should not be too greedy. For example, for a total of 8GB machines, you assign the whole 7.5GB to JVM. When the operating system runs out of memory, your JVM may become the prey of oom-killer.
However, through the following order, the process can be avoided from trial.
Echo-17 > / proc/ [pid] / oom_adj
This is because the oom_adj file, which is the weight of the process killed by oom killer, is generally between [- 17pr 15]. The higher the weight, the more likely it is to be selected by oom killer.
Once you do this, your Java process is a privileged class that can ignore the rules.
two。 Executed the God function.
Xjjdog's evaluation of this function is: better than you know it, it is worse than you don't know it.
Don't look at me for this function. I'm talking about you, System.exit.
This function is very dangerous, it will force the termination of our application, and nothing will be left. You should scan your code to make sure such logic doesn't exist.
Trust me, you don't need to use program judgment to end the process immediately, especially in business systems. If so, the probability is unreasonable. Unless you use Java as a script.
This function is a very advanced burying skill, especially in applications such as Android. When the application crashes, you can't analyze any reason, even if you do ShutdownHook.
When using the exit function, be sure to be kind.
Of course, there is nothing we can do about it. The following code, can prevent the implementation of exit, domineering extraordinary. God's hand is also broken back.
Import java.security.Permission; public class S {private static class ExitTrappedException extends SecurityException {} private static void forbidSystemExitCall () {final SecurityManager securityManager = new SecurityManager () {public void checkPermission (Permission permission) {if (permission.getName (). StartsWith ("exitVM")) {throw new ExitTrappedException ();} System.setSecurityManager (securityManager);} private static void enableSystemExitCall () {System.setSecurityManager (null);} public static void main (String [] args) {forbidSystemExitCall (); try {System.exit (0);} catch (Exception ex) {ex.printStackTrace () } System.out.println ("Thank you xjjjdog, I can still execute");}}
If you go to great lengths and can't find the reason for the abnormal termination, try hanging this code. It could be life-saving.
3. Wrong startup mode
Let's talk about one of the most basic and common situations that can lead to the unexpected death of an application: the wrong way to start a Java program.
Many students are not very familiar with Linux. After logging in using XShell, call the following command to start.
Java com.cn.AA &
The student was somewhat conscious and used the & sign at the end in order to expect the process to run in the background. Unfortunately, in many cases, as the XShell Tab page closes or waits for a timeout, the subsequent Java process stops with a piece, which is very confusing.
The correct way to start is to use the nohup keyword or block in other longer-lived processes (such as docker).
Nohup java com.cn.AA &
Therefore, when you log in to the terminal tty, be sure to figure out who the currently executing parent process is. You may be the ancestor of all the processes to run next.
4. Log configuration error
If none of the above is the reason, there is a good chance that the logging framework in your project is misconfigured. There are a variety of log frameworks and configurations in Java. If you are not careful, you will step on the pit. Even if you are using SpringBoot, it will cause startup problems because of the dependency package.
Log configuration error + exception, of course, nothing will be left.
Using the following command, you can transfer the dependency tree to a log file for analysis.
Mvn dependency:tree > dep.log
If it is a SpringBoot project, you can add some code to the main class.
Public static void main (String [] args) {try {SpringApplication.run (LinkpowerDtulockApplication.class, args);} catch (Exception e) {System.out.println (e);}}
In this way, if there is anything unusual, we can find it earlier.
In addition, there are a number of strange reasons for End. For example, the disk is full, the handle is not enough, these situations are very hidden, you need to accurately control the details of the system.
Process, a quiet way of death, usually makes it more difficult for us to troubleshoot problems.
Usually, we use "kill-15" instead of "kill-9" when shutting down the service, so that the service can catch its breath before it dies. But it doesn't always work, because the program doesn't have a chance to make last words at all, and a higher level of existence prevents it. The Java process is dead, so we have to look for other means.
This is the end of the content of "how to solve the problem that the Java process is missing". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.