我的代码在没有sleep之前,出现的结果和sleep后的结果一样,让我有点纳闷啊,是不是jdk版本的问题啊?我的是jdk1.8.
代码和运行结果如下:
class Bank
{
private int sum;
public void add(int n)
{
sum = sum+n;
System.out.println("sum="+sum);
}
}
class Cus implements Runnable
{
private Bank b = new Bank();
public void run()
{
for(int x=0;x<3;x++)
{
b.add(100);
}
}
}
class BankDemo
{
public static void main(String[] args)
{
Cus c = new Cus();
Thread t =new Thread(c);
Thread tt = new Thread(c);
t.start();
tt.start();
}
}
|
|