Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the source code of Java SynDemo object

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report