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

Java sum passes how to complete member variables

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces how to complete the member variables of Java sum transmission, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Java sum delivery requires us to continue to learn, of course, we will have a lot of problems to solve in learning. Let's take a closer look at how we can't start 100 threads better. Each thread passes an additional 1 to the variable Java sum (the sum initial value is 0). You need to pass the sum to the thread by reference.

To be able to pass references, sum is taken as a class member variable and the object of that class is passed to the thread. Use locking and unlocking to achieve the plus 1 operation, to see the final implementation effect.

* / public class Thread100Baidu {public static void main (String [] args) {int [] sum = new int [100]; MyThread [] mt = new MyThread [100]; for

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