In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article is about whether other threads can continue to work after JVM heap memory overflow, so I think it is very practical, so I share it with you. I hope you can get something after reading this article. Let's take a look at it.
Recently, an interview question for Meituan appeared online: "after one thread OOM, can other threads still run?" . I think there are a lot of unreliable answers on the Internet. This question is actually very difficult, involving knowledge points such as jvm memory allocation, scope, gc, etc., it is not a simple question of yes or no.
Because there are many types of OOM in the OOM,java given in the title, for example:
Heap overflow ("java.lang.OutOfMemoryError: Java heap space")
Permanent band overflow ("java.lang.OutOfMemoryError:Permgen space")
There are many situations where threads ("java.lang.OutOfMemoryError:Unable to create new native thread") cannot be created.
The main purpose is to analyze the impact of stack overflow on the application.
To talk about the answer first, the answer is that it still works.
The code is as follows
Public class JvmThread {public static void main (String [] args) {new Thread (()-> {List list = new ArrayList (); while (true) {System.out.println (new Date (). ToString () + Thread.currentThread () + "= ="); byte [] b = new byte [1024 * 1024 * 1]; list.add (b) Try {Thread.sleep (1000);} catch (Exception e) {e.printStackTrace ();}) .start () / / Thread 2 new Thread (()-> {while (true) {System.out.println (new Date (). ToString () + Thread.currentThread () + "= ="); try {Thread.sleep (1000);} catch (Exception e) {e.printStackTrace () ). Start ();}}
Result display
Wed Nov 07 14:42:18 CST 2018 Thread [Thread-1Power5 main] = = Wed Nov 07 14:42:18 CST 2018Thread [Thread-0Power5] = = Wed Nov 07 14:42:19 CST 2018Thread [Thread-1Power5] = = Wed Nov 07 14:42:19 CST 2018Thread [Thread-0L5] Main] = = Exception in thread "Thread-0" > at com.gosaint.util.JvmThread.lambda$main$0 (JvmThread.java:21) at com.gosaint.util.JvmThread$$Lambda$1/521645586.run (Unknown Source) at java.lang.Thread.run (Thread.java:748) Wed Nov 07 14:42:20 CST [Thread-1 Thread.java:748] = = Wed Nov 07 14:42:21 CST 2018 Thread [Thread-1 main] = = Wed Nov 07 14:42:22 CST 2018 Thread [Thread.java:748] =
JVM startup parameter settings
The figure above shows the changes in the JVM heap space. If we take a closer look at the changes in the curve between 14-42-14-42-25, you will find that the number of heaps used has suddenly dropped sharply! This means that when a thread throws an OOM exception, all the memory resources it occupies are freed so that it does not affect the running of other threads!
At this point, you should understand that the answer to this question is that after a thread overflows, other threads in the process can run as usual. Note that I only demonstrated the case of heap overflow in this example. If it is a stack overflow, the conclusion is the same, everyone can pass the code test on their own.
Summary
In fact, the thread that occurs OOM will usually die, that is, it will be terminated, and the heap occupied by the object held by the thread will be gc, freeing up memory. Because gc needs to be done before OOM occurs, even if other threads can work properly, it will have a greater impact because of frequent gc.
The above is whether other threads can continue to work after the JVM heap memory overflow. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
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.