我有 MyTimer 需要参数:
public MyTimer(long mac, String ipAddress){
this.macAddress = mac;
this.ip = ipAddress;
timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
log.info("mac " + String.valueOf(macAddress) + " ip " + ip);
}
};
timer.schedule(timerTask, 30*1000,30*1000);
log.info("timer created, mac:" String.valueOf(macAddress) + " ip " + ip);
}
从另一个班级:
MyTimer timer1 = new MyTimer(mac1, ip1);
MyTimer timer2 = new MyTimer(mac2, ip2);
创建后一切正常:
Oct 23, 2012 1:36:43 PM spb.MyTimer <init>
INFO: timer created, mac: 26954208388119 ip 77.209.184.53
Oct 23, 2012 1:36:43 PM spb.MyTimer <init>
INFO: timer created, mac 26954208388118 ip 178.139.7.27
但是,当计时器达到延迟时:
Oct 23, 2012 1:39:13 PM spb.MyTimer$1 run
INFO: mac 26954208388119 ip 178.139.7.27
Oct 23, 2012 1:39:13 PM spb.MyTimer$1 run
INFO: mac 26954208388118 ip 178.139.7.27
这个问题应该如何解决?