请帮忙看Thread问题

oDon 2006-03-31 09:09:30
import java.io.*;
import java.util.*;
public class ThreadTest implements Runnable{
int sleeptime;
int count;
int num;
public ThreadTest(int time, int timez){
int sleeptime = time;
int count = timez;
int num = 0;
}
public void run(){
System.out.println("Thread is running!");
while(num < count){
count++;
System.out.println(new Date(System.currentTimeMillis()));
Thread.sleep(sleeptime);
}
}
public void stop(){
System.out.println("Thread is dead!");
}
public static void main(String[] args){
ThreadTest tt = new ThreadTest(100,20);
tt.start();
}
}
//找不到符号
...全文
165 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuzl32 2006-03-31
  • 打赏
  • 举报
回复
呵呵.
zhonglizhi 2006-03-31
  • 打赏
  • 举报
回复
import java.io.*;
import java.util.*;

public class ThreadTest implements Runnable{
int sleeptime;
int count;
int num;
public ThreadTest(int time, int timez){
sleeptime = time; //修改处
count = timez; //修改处
num = 0; //修改处
}
public void run(){
System.out.println("Thread is running!");
while(num < count){
num++; //修改处
System.out.println(new Date(System.currentTimeMillis()));
try{
Thread.sleep(sleeptime);}//修改处
catch(Exception e){};
}
stop();//修改处
}
public void stop(){
System.out.println("Thread is dead!");
}
public static void main(String[] args){
ThreadTest tt = new ThreadTest(100,20);
Thread ttt=new Thread(tt); //修改处
ttt.start(); //修改处
}
}

楼主程序有逻辑错误 呀 已经修改好 请仔细看
interpb 2006-03-31
  • 打赏
  • 举报
回复
我晕楼主的构造函数也有问题

调试了好久

public ThreadTest(int time, int timez){
sleeptime = time;
count = timez;
num = 0;
}

要这样写啊
不然 循环永远运行不了
interpb 2006-03-31
  • 打赏
  • 举报
回复
public void run() {
System.out.println("Thread is running!");
while (num < count) {
count++;
System.out.println(new Date(System.currentTimeMillis()));
try {Thread.sleep(sleeptime);

} catch(Exception ex){
System.out.println(ex);
}
}
}

还有一个错误 加上异常处理
treeroot 2006-03-31
  • 打赏
  • 举报
回复
狂晕
zaghost 2006-03-31
  • 打赏
  • 举报
回复
ThreadTest tt = new ThreadTest(100,20);
Thread ttt=new Thread(tt);
ttt.start();
oDon 2006-03-31
  • 打赏
  • 举报
回复
逻辑错误看到了 :)
按zhonglizhi(111)的改法 还是有错误!
无法访问Thread line 19
crazycy 2006-03-31
  • 打赏
  • 举报
回复
收到 谢谢 嘿嘿

62,629

社区成员

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

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