public class Program {
public static Tuser user = new Tuser();
public static void main(String[] args) throws InterruptedException {
new Thread(
new Runnable(){
public void run(){
while(true){
String s = get();
if (user.getUsername().equals("hehe")) {
System.out.println("成功");
//break;
}
}
}
}
).start();
Thread.sleep(1000);
new Thread(new Runnable(){
@Override
public void run(){
user.setUsername("hehe");
user=null;
}
}).start();
}
public static synchronized String get(){
return user.getUsername();
}
}三个渐进式问题: 1.执行后什么结果 2 为什么 3 去掉get方法的synchronized会怎么样?
添加回答
举报
0/150
提交
取消