Java Virtual Machine Doesn’t Exit

Java Virtual Machine Doesn’t Exit

You may have been surprised and frustrated to find that in some cases, the Java Virtual Machine (JVM) does not stop running when your application exits the static main() method. For example:

 public class FrameTest extends java.awt.Frame {	public static void main(String[] args) {		FrameTest ft = new FrameTest();		ft.setVisible(true);		ft.setVisible(false);		ft.dispose();		ft = null;	}  //  public static void main()}  //  public class FrameTest extends java.awt.Frame

When this code is run as an application, the JVM will not exit. However, it will exit if you delete the calls to setVisible() and run it again. The reason for this change in behavior is that making the Frame visible activates the event thread, which is responsible for calling event handler methods and for painting. Once the event thread is running, the JVM doesn’t exit because the event thread is not a daemon thread, and the JVM only exits when no daemon threads are running. To force the JVM to exit, you should call the System.exit() method, which takes a single integer value as a parameter. For example:

 public class FrameTest extends java.awt.Frame {	public static void main(String[] args) {		FrameTest ft = new FrameTest();		ft.setVisible(true);		ft.setVisible(false);		ft.dispose();		ft = null;		System.exit(0);	}  //  public static void main()}  //  public class FrameTest extends java.awt.Frame
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes