由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - Basic thread question
相关主题
怎么练习java multithreadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
multi-threading guru们 (转载)怎么可以练习多线程编程呢?
怎么学multithreading/concurrency?求问如何学习multithreading
Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runnjava concurrency (转载)
question on single thread & multithreadApply lock on a class.
如何让两个socket并行执行threadConverge of languages and design pattern
有关thread in Java请问如何避免这样的style
a Java MultiThreading questionjava 写unit test 给clover 真就是农民阿
相关话题的讨论汇总
话题: int话题: private话题: calc话题: class话题: static
进入Java版参与讨论
1 (共1页)
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;

1 (共1页)
进入Java版参与讨论
相关主题
java 写unit test 给clover 真就是农民阿question on single thread & multithread
array 在java里 是一定放在heap 吗?如何让两个socket并行执行thread
Re: How to lock a file and detect a thread is over?有关thread in Java
[转载] 现在还有什么OS不是THREAD级调度的吗?a Java MultiThreading question
怎么练习java multithreadHow to ues log4j to send log email in the multithreaded processes as similiar with single-threaded
multi-threading guru们 (转载)怎么可以练习多线程编程呢?
怎么学multithreading/concurrency?求问如何学习multithreading
Re: Help!!! Java in Unix. Thread. I need exit and ls concurrently runnjava concurrency (转载)
相关话题的讨论汇总
话题: int话题: private话题: calc话题: class话题: static