我写了一个定时任务,然后定时任务执行时
说没有活动的方法上下文
定时任务如下
public class TestTask3 extends TimerTask {
private static boolean isRunning = false;
@Override
public void run() {
// 是否整点
// Calendar c = Calendar.getInstance();
// if (C_SCHEDULE_HOUR == c.get(Calendar.HOUR_OF_DAY))
if (!isRunning) {
isRunning = true;
com.lcs.wc.material.LCSMaterial lcsMaterial = null;
try {
lcsMaterial = (com.lcs.wc.material.LCSMaterial) com.lcs.wc.foundation.LCSQuery.findObjectById("VR:com.lcs.wc.material.LCSMaterial:9252102");
} catch (WTException e) {
e.printStackTrace();
}
String name1 = lcsMaterial.getName();
System.out.println(name1);
isRunning = false;
}
}
}
public class test11 implements ServletContextListener {
private Timer timer = null;
@Override
public void contextInitialized(ServletContextEvent event) {
timer = new Timer(true);
event.getServletContext().log("定时器已启动");
timer.scheduleAtFixedRate(new TestTask3(), 60*1000 , 1000 * 60); // 每小时执行一次run方法 测试5秒5 * 1000
}
@Override
public void contextDestroyed(ServletContextEvent event) {
if (timer != null) {
timer.cancel();
event.getServletContext().log("定时器销毁");
}
}
}
执行Java代码是可以的,但是只要调用windchill上的方法jiu'hui'bao'cuo