Java sum passes how to complete member variables
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