TimerTask 的问题
大家好,我使用 RuleStudio(修改版 Eclipse)在 IBM Websphere ILOG JRules 7.0 中工作,并且在尝试实现 TimerTask 时遇到问题。
我根据我知道有效的不同规则创建了一个技术规则,并尝试添加一些等待 5 秒然后发送辅助消息的代码。我通过以下代码尝试了这一点:
int interval = 5000; // 5 sec
java.util.Date timeToRun = new java.util.Date(System.currentTimeMillis() + interval);
java.util.Timer timer = new java.util.Timer();
timer.schedule(new java.util.TimerTask() {
public void run() {
// Message Sent Here
}
}, timeToRun);
但是,该代码无法编译。它指出的错误位于 new java.util.TimerTask()
之后的开括号中,错误消息位于 标记“{”
处。
不过,有一些有趣的观察结果:
- 我尝试执行 java.util.TimerTask test = new java.util.TimerTask(); ,它在 new java.util.TimerTask(); 处抛出错误。 说无法找到java.util.TimerTask的公共构造函数(或参数不匹配)。
我觉得这很奇怪,因为它确实是导入的。
-如果重要的话,我在我的电脑上安装了 Java 版本 1.6.0_17。
谢谢!
Hey all, Im working in IBM Websphere ILOG JRules 7.0 using RuleStudio (modified Eclipse) and am having an issue trying to implement a TimerTask.
I created a Techincal Rule based off a different rule that I know works and tried to add some code that would wait 5 seconds and then send a secondary message. I tried this via the following code:
int interval = 5000; // 5 sec
java.util.Date timeToRun = new java.util.Date(System.currentTimeMillis() + interval);
java.util.Timer timer = new java.util.Timer();
timer.schedule(new java.util.TimerTask() {
public void run() {
// Message Sent Here
}
}, timeToRun);
However, this code does not compile. The error it points out is on the open bracket right after new java.util.TimerTask()
and the error messag is at token "{"
.
Some interesting observations though:
-I tried doing java.util.TimerTask test = new java.util.TimerTask();
and it throws an error at new java.util.TimerTask();
saying Could not find a public constructor (or argument mismatch) for java.util.TimerTask.
Which I find odd since it's defintaly imported.
-I have Java version 1.6.0_17 installed on my comp, if it matters.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有使用 ILOG 的经验,但我猜测这可能会更好:
如果仍然不起作用,请从方法中取出
MyTask
。I have no experience with ILOG, but I'm guessing that this will probably work better:
If that still doesn't work, take
MyTask
out of the method.注意到它仍然是打开的,结果发现我们使用的引擎有一个定制的 java 库,其中不包括 TimerTask...doh。使用库实际拥有的线程睡眠命令。
Noticed this was still open, turned out that the engine we were using has a customized java library on it that didnt include TimerTask... doh. Went with a thread sleep command that the library actually had.