我在向一个Vector添加数据的时候,系统提示我:在使用ADD方法之前没有检查,代码如下:
public static void enQueue(String str)
{
synchronized (v1 )
{ while( v1.size()>=100*1024 )
{
System.out.print("Waiting..........");
try{
v1.wait();
}catch(Exception e)
{e.printStackTrace();}
//while
} // v1.addElement(obj);
v1.add(str);
// System.out.println(String.valueOf(v1.firstElement()));
v1.notifyAll();
// thread = new CreateThread(IP,PORT);
// thread.start();
}
}
public static void enQueue(String str)
{
synchronized (v1 )
{ while( v1.size()>=100*1024 )
{
System.out.print("Waiting..........");
try{
v1.wait();
}catch(Exception e)
{e.printStackTrace();}
//while
} // v1.addElement(obj);
v1.add(str);
// System.out.println(String.valueOf(v1.firstElement()));
v1.notifyAll();
// thread = new CreateThread(IP,PORT);
// thread.start();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货