Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand the source code of Java SynDemo object

Shulou Source: shulou.com Published: 2022-06-02 12:40:21 10月31日 Update

This article shows you how to understand the Java SynDemo object source code, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

Java SynDemo objects have always been used in our language, but in fact, we can still find answers to relevant questions in the source code as we continue to learn. Our Java SynDemo object does not have any special definition, so what happens when it is run is as follows:

SynMethord2 synMethord1 main synMethord2 synMethord1 main synMethord2 synMethord1

Next, we add a synchronized declaration to synMethord1, which runs the same as last time, because we only have one thread calling the synMethord1 method.

We also add a synchronized declaration to synMethord2, and the code of the SynDemo object is modified to:

Package com.cnblogs.gpcuster;/** @ author Aaron.

Guo * * /

Public class SynDemo {public synchronized void

SynMethord1 () {while (true) {try {Thread.sleep (1000)

System.out.println ("synMethord1");} catch (Interrupted

Exception e) {/ / TODO Auto-generated catch block

E.printStackTrace ()

}

}

}

Public synchronized void synMethord2 () {while (true)

{try {Thread.sleep (1000); System.out.println ("synMeth

Ord2 ");} catch (InterruptedException e) {/ / TODO

Auto-generated catch block

E.printStackTrace ()

}

}

}

}

The above is how to understand the source code of Java SynDemo objects. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Tags: Object source code content situation skills knowledge or run special concise next concise continuous code only that is articles methods more answers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker vpn Xiaomi Shulou Technology