start() 和 system.out 的优先级别

xuhui54 xuhui54 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
结果怎么是
Totle Money: 100.0
100.0
100.0
7
1
100.0
withdraw 100 success
0.0
withdraw 100 failed!
附带代码
package two;

public class Account {

double balance;

public Account(double money){
// System.out.println(6);
balance = money;
System.out.println("Totle Money: "+balance);
// System.out.println(3);
}
public void ba() {

System.out.println(balance);
}
public void withdraw(double money){
// System.out.println(2);
synchronized (this) {
if (balance >= money) {
balance = balance - money;
// System.out.println(4);
System.out.println("withdraw 100 success");
}
else
System.out.println("withdraw 100 failed!");
}
}
}


package two;

public class AccountThread extends Thread {

Account acount;
public AccountThread(Account acount) {
// System.out.println(5);
this.acount = acount;
acount.ba();

}
public void run(){
acount.ba();
acount.withdraw(100);
}

}



package two;

public class Tst {

/**
* @param args
*/
public static void main(String[] args) {

Account acount = new Account(100);

AccountThread acountThread31 = new AccountThread(acount);
AccountThread acountThread32 = new AccountThread(acount);
System.out.println(7);
acountThread31.start();
System.out.println(1);
acountThread32.start();
}

}

...全文

相关推荐

评论 6
收藏 已收藏
分享
返回顶部
xuhui54
Java SE 62,621 成员 307,251 内容