也许我不理解这一点,但是没有记录样本,所以我不得不玩它。我创建了一个将用作XOTS tasklet的类:
package org.sutol.demo.xots;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import org.openntf.domino.xots.Tasklet;
import org.openntf.domino.xsp.XspOpenLogUtil;
@Tasklet(session = Tasklet.Session.CLONE, schedule = "cron:0 */1 00-23 * * *")
public class PeriodicTask implements Callable<String> {
public String call() {
Calendar now = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss");
String result = "Message from PeriodicTask: " + formatter.format(now.getTime());
createOutput(result);
return result;
}
private void createOutput(String msg) {
System.out.println(msg);
XspOpenLogUtil.logEvent(null, msg, Level.INFO, null);
}
}
当我使用Xots对象的schedule方法时使用此类:
public static void testPeriodicTasklet() {
Xots.getService().schedule(new PeriodicTask(), 1, TimeUnit.SECONDS);
}
这里有几个问题:
服务器控制台上的错误消息:
08.11.2015 18:59:39 HTTP JVM: ### LOGSTART
08.11.2015 18:59:39 HTTP JVM: Message from PeriodicTask: 08.11.2015, 18:59:39
08.11.2015 18:59:39 HTTP JVM: INIT
08.11.2015 18:59:39 [ODA::WARNING] null
08.11.2015 18:59:39 [ODA::WARNING] (source:org.openntf.domino.utils.DominoUtils$4.run - See IBM_TECHNICAL_SUPPORT\org.openntf.log.X.Y.txt for full stack trace.)
08.11.2015 18:59:39 HTTP JVM: ### LOGSUCCESS
这是日志文件的内容:
2015-11-08T18:59:39 [WARNING]: com.ibm.xsp.util.FacesUtil.resolveVariable - null
java.lang.NullPointerException
at com.ibm.xsp.util.FacesUtil.resolveVariable(FacesUtil.java:1048)
at com.ibm.xsp.designer.context.XSPContext.getXSPContext(XSPContext.java:59)
at com.ibm.xsp.extlib.util.ExtLibUtil.getXspContext(ExtLibUtil.java:202)
at org.openntf.domino.xsp.XspOpenLogItem.setThisAgent(XspOpenLogItem.java:132)
at org.openntf.domino.xsp.XspOpenLogItem.getThisAgent(XspOpenLogItem.java:124)
at org.openntf.domino.xsp.XspOpenLogItem.writeToLog(XspOpenLogItem.java:419)
at org.openntf.domino.logging.BaseOpenLogItem.logEvent(BaseOpenLogItem.java:685)
at org.openntf.domino.xsp.XspOpenLogUtil.logEvent(XspOpenLogUtil.java:134)
at org.sutol.demo.xots.PeriodicTask.createOutput(PeriodicTask.java:24)
at org.sutol.demo.xots.PeriodicTask.call(PeriodicTask.java:18)
at org.sutol.demo.xots.PeriodicTask.call(PeriodicTask.java:1)
at org.openntf.domino.xsp.xots.XotsWrappedTask.invokeObject(XotsWrappedTask.java:145)
at org.openntf.domino.xsp.xots.XotsWrappedTask.invokeTasklet(XotsWrappedTask.java:125)
at org.openntf.domino.xsp.xots.XotsWrappedTask.callOrRun(XotsWrappedTask.java:55)
at org.openntf.domino.xsp.xots.XotsDominoExecutor$XotsWrappedCallable.call(XotsDominoExecutor.java:62)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
at java.util.concurrent.FutureTask.run(FutureTask.java:149)
at org.openntf.domino.thread.AbstractDominoExecutor$DominoFutureTask.run(AbstractDominoExecutor.java:235)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:583)
at java.security.AccessController.doPrivileged(AccessController.java:384)
at java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:580)
at java.lang.Thread.run(Thread.java:767)
有人可以告诉我一个更好的样本或我在这里做错了什么吗? 我想点击一个按钮开始定期任务(当然我想停止点击另一个按钮,但这不是我想出怎么做的。)
答案 0 :(得分:1)
删除对XspOpenLogUtil.logEvent的调用 它在Xots上下文中不可用
答案 1 :(得分:1)
Xots中没有XspContext。所有与XPage相关的元素,如resolveVariable使用的VariableResolver都需要以某种方式实例化。更复杂的是,他们需要使用与XPage运行时相同的ClassLoader进行实例化,否则它们将是XPages元素的单独实例,因此applicationScope将是一个单独的applicationScope,随后无法从XPage访问。我倾向于传入任何XPage-runtime对象,并让我的实用程序方法使用try / catch来转到XPage运行时,否则就是Xots任务的相关属性。
答案 2 :(得分:0)
我的错,我被困了。
当我自动完成Xots类的调度方法时,我偶然使用了错误的方法。这是#include<stdio.h>
int main() {
int i, j, n;
scanf("%d",&n);
for (i=0;i<=n;i++){
for (j=0;j<=i;j++){
printf("*");
}
printf("\n");
}
return 0;
}
而非java.util.concurrent
我改为正确的方法,需要像这样的PeriodicScheduler:
org.openntf.domino.thread
使用此方法,代码每秒执行一次。现在我只需要弄清楚如何阻止:-D