我有一個按小時運行的工作。我想要麼像這樣調用Controller的Action方法:Play Framework:從作業中呼叫控制器/ URL
public class MyJob extends Job {
@Override
public void doJob() throws Exception {
MyController.someActionMethod();
}
}
或直接調用URL。
任何想法,如果這可以從一個工作內?
如果我把一個控制器的操作方法直接,我得到這個:
NullPointerException occured : null
play.exceptions.JavaExecutionException
at play.jobs.Job.call(Job.java:155)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:207)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at play.classloading.enhancers.ControllersEnhancer$ControllerInstrumentation.isActionCallAllowed(ControllersEnhancer.java:187)
at controllers.MyController.someActionMethod(MyController.java)
at fun.job.MyJob.doJob(MyJob.java:10)
at play.jobs.Job.doJobWithResult(Job.java:50)
at play.jobs.Job.call(Job.java:146)
... 7 more
我試過了,對於外部URL(比如Yahoo),似乎可以正常工作,但對於同一服務器上的URL,也就是調用我自己的控制器操作方法,正如OP描述的那樣。在調試器中逐步完成作業顯示,它在調用get()時掛起,並最終在60秒後超時。有任何想法嗎? –