Question

What else do I have to do, other than making a cron.xml file for scheduling ? I am getting the same exception:

java.security.AccessControlException: access denied 
("java.lang.RuntimePermission" "modifyThreadGroup")

as I was getting before.

This is my cron.xml :

<?xml version="1.0" encoding="UTF-8"?>
<cronentries>
    <cron>
        <url>/tw</url>
        <description>Tweet every half an hour</description>
        <schedule>every 30 minutes from 8:00 to 17:00</schedule>
    </cron>
</cronentries>

/tw is the servlet that has a doGet method which uses java.util.Timer to schedule the task.

Was it helpful?

Solution

You have to not use Timer (or anything else that uses threads via the normal Java API). AppEngine doesn't allow creation of additional threads as part of a request except via its own special interface (and they're not allowed to outlive the request).

The point of crons is that they're already called once for each time they're supposed to happen. You don't need to do any further "scheduling" in the servlet - just do what you want to happen when the cron fires.

OTHER TIPS

I think you're doing this a bit wrong. Cron is used to specify at what intervals/time a servlet will be called. So, your actual servlet needs to do the work (i.e. send a tweet) and cron service will make sure it's called at correct times.

You can use threads, subject to restrictions described in The Sandbox. But you may not need to use threads at all. Schedule the work using a Push Queue. To reduce platform overheads, AppEngine overprovisioning may start either your cron task or your queued task multiple times, so your logic may need to take extra precautions to avoid sending duplicate tweets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top