一下是我为了验证多线程的程序 请大家帮我看看怎么改才能正常运行 我想运行出第一个线程是打印是个0 后一个线程是打印出0到9
第一个文件
public class MyThread extends Thread{
public int x=0;
public void run()
{
System.out.println(x++);
}class R implements Runnable{
private int x=0;
public void run(){
System.out.println(x++);
}
}
}
第二个文件:public class Test1 { public static void main(String[] args) throws Exception{
//创造对象来实现线程的启动
for(int i=0;i<10;i++){
Thread t =new MyThread();
t.start();
}
Thread.sleep(10000);
R r=new R(); //这句报错
for(int i=0;i<10;i++){
Thread t=new Thread(r);
t.start();
}
}}
第一个文件
public class MyThread extends Thread{
public int x=0;
public void run()
{
System.out.println(x++);
}class R implements Runnable{
private int x=0;
public void run(){
System.out.println(x++);
}
}
}
第二个文件:public class Test1 { public static void main(String[] args) throws Exception{
//创造对象来实现线程的启动
for(int i=0;i<10;i++){
Thread t =new MyThread();
t.start();
}
Thread.sleep(10000);
R r=new R(); //这句报错
for(int i=0;i<10;i++){
Thread t=new Thread(r);
t.start();
}
}}
解决方案 »
- 类实现java.io.Serializable后的一个问题
- 参数传递问题,迷惑了。
- ObjectOutputStream 的小例子,不太明白
- 关于java和c++的问题?
- 用microsoft的JDBC驱动访问SQL数据库,为什么数据集的一些功能用不了了?
- 在javascript中如何将字符串转换成数值
- jsf 显示的问题
- 如何设置让BufferedReader和PrintWriter对指定目录进行文本读写
- 一个简单的jar包提问,但是我还在困惑中.......
- 如何用Java通过POST方法向HTTP接口传递数据?
- 求源码,用java定义形状类,随机产生圆,椭圆、矩形,并输出中心点、面积、周长
- pbm格式的文件怎么读呀?
public class MyThread extends Thread{
public int x=0; public void run()
{
System.out.println(x++);
}}
class R implements Runnable{
private int x=0;
public void run(){
System.out.println(x++);
}
}