菜鸟一枚,路过的大虾帮忙看一下
package xiancheng;public class Testsyn implements Runnable(){//为什么实现一个接口他还报错呀
Timer timer = new Timer();//这个地方它显示的是分号错了
public static void main(String[] args) {
// TODO Auto-generated method stub
Testsyn t = new Testsyn();
Thread t1 = new Thread(t);
Thread t2 = new Thread(t);
t1.setName("t1");
t2.setName("t2");
t1.start();
t2.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
timer.add(Thread.currentThread().getName());
}
}
class Timer{
private static int num = 0;
public void add(String name){
num++;
try{
Thread.sleep(1);
}catch(InterruptedException e){
System.out.println(name +"是第"+"num"+"个访问者");
}
}
}