这是我的代码
import java.util.concurrent.SynchronousQueue;
public class Mywork {
public static void main(String args[])
{
SynchronousQueue<String> s=new SynchronousQueue<>();
Producer1 p1 =new Producer1(s);
Producer2 p2=new Producer2(s);
new Thread(p1).start();
new Thread(p2).start();
}
}
class Producer1 implements Runnable
{
SynchronousQueue<String> s=null;
Producer1(SynchronousQueue<String> q)
{
this.s=q;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
s.put("Suman");
System.out.println(s);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//
class Producer2 implements Runnable
{
SynchronousQueue<String> s=null;
Producer2(SynchronousQueue<String> q)
{
this.s=q;
}
@Override
public void run() {
// TODO Auto-generated method stub
try {
s.put("Ghosh");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
每当执行put之后我就不能调试它,控件就会从日食中消失
知道为什么会这样吗?
fillna