Deadlock caused by simple instances on java virtual machines

Source: Internet
Author: User

First, use internal classes to add inheritance relationships

 
Class A {protected class B extends a {// public B () {system. out. println ("This is B constructor") ;}} public B = new B (); Public A () {// system. out. println ("this is a constructor") ;}} public class testinnerclass {public static void main (string ARGs []) {New ();}}

Second, use the normal class to add inheritance

 
Class A {public testdeadlock T = new testdeadlock ();} public class testdeadlock extends a {public static void main (string ARGs []) {New ();}}

Or:

 
Class A {public a () {testdeadlock T = new testdeadlock () ;}} public class testdeadlock extends a {public static void main (string ARGs []) {New ();}}

 

Third, it can be implemented without constructors or inheritance.

Class blocked {public interrupt = new interrupt ();} public class interrupt {blocked B = new blocked (); public static void main (string [] ARGs) {New blocked ();}}

 

 

Conclusion: The inheritance relationship is used to bring deadlocks to the parent and child classes.

Instantiating a subclass in the parent class is the root cause of deadlock.

In fact, resources compete with each other to form an endless loop

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.