Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the <a href="http://docs.oracle.com/javase/6/docs/api/java/util/Timer.html">documentation of <code>java.util.Timer</code> class</a>:</p> <blockquote> <p>Corresponding to each Timer object is a single background thread.</p> </blockquote> <p>And <a href="http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/util/Timer.java#100">peeking to the inner code of the <code>java.util.Timer</code> class</a>, we can see that it basically instantiates the thread by invoking <code>new Thread()</code>.</p> <p>Meanwhile, from <a href="https://developers.google.com/appengine/docs/java/runtime#The_Sandbox">App Engine's documentation</a> about the use of threads in their Java sandbox:</p> <blockquote> <p>You must use one of the methods on <a href="https://developers.google.com/appengine/docs/java/javadoc/com/google/appengine/api/ThreadManager">ThreadManager</a> to create your threads. <strong>You cannot invoke new Thread() yourself</strong> or use the default thread factory.</p> </blockquote> <p>So what happened here is the <code>Timer</code> object instantiated their own thread, which then executes the Objectify queries, but since threads instantiated outside ThreadManager does not have the proper App Engine API environment set up for them, it throws an exception.</p> <p>You need to refactor your code to avoid using the Timer and TimerTask classes and use basic threads instead. For example, instead of using:</p> <pre><code>import java.util.Timer; import java.util.TimerTask; ... Timer timer = new Timer(); timer.schedule( new TimerTask() { @Override public void run() { // Objectify query here. } }, 5000 ); </code></pre> <p>You could instead use:</p> <pre><code>import com.google.appengine.api.ThreadManager; ... final long tScheduleDelay = 5000; ThreadManager.createThreadForCurrentRequest( new Runnable() { @Override public void run() { try { Thread.sleep( tScheduleDelay ); } catch ( InterruptedException ex ) { // log possible exception } // Objectify query here. } } ).start(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload