w**i 发帖数: 80 | 1 In the Java class below, an instance of this class is created on each of 3 threads. I need some help to find any likely serious problem these threads will have with using the Calc mehtod. And what is a good solution?
public class doSomething {
private static int w = 1;
private int x = 1;
private static int y = 100;
private int z = 100;
public int Calc() {
int total = 0;
total = (w * y) + (x * z);
w = w + 1;
x = x + 1;
return (tot | w*******g 发帖数: 9932 | 2 why use static variable w and y?
【在 w**i 的大作中提到】 : In the Java class below, an instance of this class is created on each of 3 threads. I need some help to find any likely serious problem these threads will have with using the Calc mehtod. And what is a good solution? : public class doSomething { : private static int w = 1; : private int x = 1; : private static int y = 100; : private int z = 100; : public int Calc() { : int total = 0; : total = (w * y) + (x * z); : w = w + 1;
| m******t 发帖数: 2416 | 3
Because it's an interview question?
【在 w*******g 的大作中提到】 : why use static variable w and y?
| c*****t 发帖数: 1879 | 4 Since you don't have any experiences in this subject, I'd suggest you
to read a book:
"Foundations of Multithreaded, Parallel, and Distributed Programming"
Covers C, Java, pthread, MPI and many other things.
【在 w**i 的大作中提到】 : In the Java class below, an instance of this class is created on each of 3 threads. I need some help to find any likely serious problem these threads will have with using the Calc mehtod. And what is a good solution? : public class doSomething { : private static int w = 1; : private int x = 1; : private static int y = 100; : private int z = 100; : public int Calc() { : int total = 0; : total = (w * y) + (x * z); : w = w + 1;
|
|