avatar
g*e
2
public class Test extends Thread{
static String sName = "good";
public static void main(String argv[]) {
Test t = new Test();
t.start();
System.out.println(sName);
}

public void run() {
for (int i = 0; i < 2; i++) {
sName = sName + " " + i;
}
}
}
这个输出难道不是good, good 0, good 0 1的任何一种吗。答案只有good
avatar
c*l
3
Electrochemical investigation of contact angle and of flotation in the
presence of alkylxanthates. I. Platinum and gold surfaces
JR Gardner and R Woods
Aust. J. Chem., 27 (1974)2139
avatar
j*a
4
i dont get it.
avatar
q*u
5
this is interesting, I have run it under win7, mac os 10 and ubuntu 8 within
eclipse, all only 'good' printed out.

public class Test extends Thread{
static String sName = "good";
public static void main(String argv[]) {
Test t = new Test();
t.start();
System.out.println(sName);
}

public void run() {
for (int i = 0; i < 2; i++) {
sName = sName + " " + i;


【在 g**e 的大作中提到】
: public class Test extends Thread{
: static String sName = "good";
: public static void main(String argv[]) {
: Test t = new Test();
: t.start();
: System.out.println(sName);
: }
:
: public void run() {
: for (int i = 0; i < 2; i++) {

avatar
f*m
6
呵呵,你print两遍sName看看什么结果

within

【在 q*********u 的大作中提到】
: this is interesting, I have run it under win7, mac os 10 and ubuntu 8 within
: eclipse, all only 'good' printed out.
:
: public class Test extends Thread{
: static String sName = "good";
: public static void main(String argv[]) {
: Test t = new Test();
: t.start();
: System.out.println(sName);
: }

avatar
q*u
7
under mac os and ubuntu8, there are:
good
good
and
good
good 0 1
i don't want reboot to win for testing, it's silly.
with one println, only 'good' is printed, but 2 println shows the difference

【在 f****m 的大作中提到】
: 呵呵,你print两遍sName看看什么结果
:
: within

avatar
g*g
8
Doesn't really prove anything, put a sleep before println.
The result will vary.

difference

【在 q*********u 的大作中提到】
: under mac os and ubuntu8, there are:
: good
: good
: and
: good
: good 0 1
: i don't want reboot to win for testing, it's silly.
: with one println, only 'good' is printed, but 2 println shows the difference

avatar
q*u
9
yes,
but with only one println, the result is not so unpredictable.
should i just consider this is just a un-flexible thread schedule?

Doesn't really prove anything, put a sleep before println.
The result will vary.
difference

【在 g*****g 的大作中提到】
: Doesn't really prove anything, put a sleep before println.
: The result will vary.
:
: difference

avatar
g*e
10
是的,sleep不同时间,output不同,而且还会变化,在windows下

【在 g*****g 的大作中提到】
: Doesn't really prove anything, put a sleep before println.
: The result will vary.
:
: difference

avatar
s*n
11
what's the possible outputs of the following program
class Test extends Thread
{
static String s = "good";
static int i = 0;
public void run()
{
s = "better";
i++;
}
public static void main(String argv[]) throws Exception
{
Test t = new Test();
t.start();
while(NOTDONE)
Thread.sleep(1000);
System.out.println(s);
}
}
if the NOTDONE expression is actually:
1) i==0
2) s.equals("good")
3) t.isAlive()
avatar
g*e
12
你回答我的问题了吗

【在 s******n 的大作中提到】
: what's the possible outputs of the following program
: class Test extends Thread
: {
: static String s = "good";
: static int i = 0;
: public void run()
: {
: s = "better";
: i++;
: }

avatar
s*n
13
all 3 cases are possible.

【在 g**e 的大作中提到】
: 你回答我的问题了吗
avatar
s*n
14
Anybody? This is not easy. If you can answer all 3 questions correctly, you
are a master of java concurrency, or at least you can play one on internet.

【在 s******n 的大作中提到】
: what's the possible outputs of the following program
: class Test extends Thread
: {
: static String s = "good";
: static int i = 0;
: public void run()
: {
: s = "better";
: i++;
: }

avatar
l*3
15
I think all three answers r better, right?

you

【在 s******n 的大作中提到】
: Anybody? This is not easy. If you can answer all 3 questions correctly, you
: are a master of java concurrency, or at least you can play one on internet.

avatar
s*n
16
no.

【在 l****3 的大作中提到】
: I think all three answers r better, right?
:
: you

avatar
l*3
17
my understanding is if NOTDONE is true, thread.sleep will put main thread to
pause for at least 1 second, which will give test thread enough time to
complete. if NOTDONE is false, which means test thread is done. so all three
answers r better. could you elaborate your thoughts? thanks.

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