获得徽章 0
public class TestForGuardedObject {

public static void main(String[] args) {
GuardedObject guardedObject = new GuardedObject();

new Thread(()->{
Object o = guardedObject.get();
System.out.println(o);
},"t1").start();


new Thread(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
guardedObject.set("张楚");
System.out.println("我是张楚,我已进来");
},"t2").start();
}
}

class GuardedObject{
private Object response;

public Object get(){
while(this.response == null){
System.out.println("GuardedObject中:" + response);
}
return response;
}

public void set(Object response){
this.response = response;
}

}
有没有佬帮忙看一下这段代码,为啥我删除get方法中的System.out就会卡死,不删除就能正常生产和消费
展开
评论
xdm,c#或者java怎么通过注册表接受参数呀,最近有一个软件加到windows注册表里了,想从中接受参数,知道怎么传参,但是不知道怎么接收参数
评论
如何在前端通过协议调用一个本机软件呢,效果就是,如果本机有就直接调起来,如果本机没有该软件则提示下载。现在我们实验室就有一个项目要实现一个功能,甲方那边给了一个协议
1
如何在前端通过协议调用一个本机软件呢,效果就是,如果本机有就直接调起来,如果本机没有该软件则提示下载。现在我们实验室就有一个项目要实现一个功能,甲方那边给了一个协议
评论
public static void main(String[] args) {
// String s1 = new String("ab");//执行完以后,会在字符串常量池中会生成"ab"
String s1 = new String("a") + new String("b");////执行完以后,不会在字符串常量池中会生成"ab"
String s = s1.intern();
String s2 = "ab";

System.out.println(s1 == s2);//true
System.out.println(s == s2);//true
}
public static void main(String[] args) {
// String s1 = new String("ab");//执行完以后,会在字符串常量池中会生成"ab"
String s1 = new String("a") + new String("b");////执行完以后,不会在字符串常量池中会生成"ab"
String s2 = "ab";
String s = s1.intern();


System.out.println(s1 == s2);//false
System.out.println(s == s2);.//true
}
有大佬知道为什么这两个代码结果不一样是为啥吗?为什么交换s和s2的声明之后就不一样了
展开
5
下一页
个人成就
文章被点赞 17
文章被阅读 4,882
掘力值 177
收藏集
2
关注标签
3
加入于