为什么v2里面获取不了几个线程的数据???怎样才能获取到

dlgz888 2009-09-24 11:39:41
import java.util.Vector;


public class TestRunnable implements Runnable{
public String name;
static Vector v=new Vector();
static Vector v2;
public TestRunnable(String n)
{
this.name=n;

}

public TestRunnable()
{


}
public void run() {
// TODO Auto-generated method stub
write(name);

}
public synchronized void write(String name){
int i=0;
while(true){
System.out.println(this.name+" --");
try {
v.add(i);
i++;
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public static void main(String args[]){
TestRunnable t2 = new TestRunnable();
v2=v;
for(int i=0;i<v2.size();i++)
System.out.println(v2.get(i));
}

public void goToC(){
TestRunnable t1=new TestRunnable("t1");
Thread th1=new Thread(t1,"t1");
th1.start();
TestRunnable t2=new TestRunnable("t2");
Thread th2=new Thread(t2,"t2");

th2.start();
TestRunnable t3=new TestRunnable("t3");
Thread th3=new Thread(t3,"t3");
th3.start();


}
}
为什么v2里面获取不了几个线程的数据???怎样才能获取到
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxlion 2009-09-24
  • 打赏
  • 举报
回复

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧