avatar
Basic thread question# Java - 爪哇娇娃
w*i
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
avatar
w*g
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;

avatar
m*t
3

Because it's an interview question?

【在 w*******g 的大作中提到】
: why use static variable w and y?
avatar
c*t
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;

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。