[英]ThreadPool Executor not executing threads in GAE
I am trying to use executor framework in Google App engine. 我正在尝试在Google App引擎中使用执行程序框架。 Bellow is the code that I am trying to run.
贝娄是我正在尝试运行的代码。
Thread thread = ThreadManager.createBackgroundThread(new Runnable(){
public void run(){
try{
LOGGER.info( "Checking background thread");
Thread.sleep(10);
}
catch (InterruptedException ex){
throw new RuntimeException("Exception:", ex);
}
}
});
ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(10, ThreadManager.backgroundThreadFactory());
executor.scheduleAtFixedRate(thread, 0, 30, TimeUnit.MINUTES);
But this doesn't start the thread. 但这不会启动线程。 But if I use thread.start() it works properly.
但是,如果我使用thread.start(),它可以正常工作。 I have checked Whitelisted Classes and it does provide Executor classes.
我检查了列入白名单的类 ,它确实提供了执行器类。 So where I am doing it wrong ?
那么,我在哪里做错了?
Saikat, Saikat,
You should always try to avoid creating threads on App Engine, because of it's distributed and dynamic nature it tends to have really bad/unexpected results. 您应始终避免在App Engine上创建线程,因为它具有分布性和动态性,因此往往会产生非常不好的/意外的结果。
In your case multiple instances will spawn multiple (local) threads sending many times the same notification. 在您的情况下,多个实例将产生多个(本地)线程,发送多次相同的通知。 Also, bear in mind GAE front end instances have a 1 minute request limit , so after that time the server will kill that request.
另外,请记住GAE前端实例的请求限制为1分钟 ,因此在那之后服务器将终止该请求。
Fortunately App Engine provides the Cron service for exactly this situations. 幸运的是,App Engine在这种情况下提供了Cron服务 。
The Cron Service will allow you to schedule a job to run at a given time or every given period. Cron服务可让您安排作业在给定的时间或每个给定的时间段运行。 When the cron is triggered GAE will call a configured URL so you can do your process, in your case send notifications.
触发cron时,GAE将调用已配置的URL,以便您可以进行处理(在这种情况下,请发送通知)。
Eg:(from the link provided) 例如:(通过提供的链接)
<cron>
<url>/weeklyreport</url>
<description>Mail out a weekly report</description>
<schedule>every monday 08:30</schedule>
<timezone>America/New_York</timezone>
</cron>
will make an HTTP request to /weeklyreport every monday @8:30. 会在每个星期一@ 8:30向/ weeklyreport发出HTTP请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.