title: Java GAE: Process terminated because the backend took too long to shutdown
body: <p>i'm running a long Task (about 6 hours) in a Backend Instance in my Google Appengine Application.</p>
  
  <p>Here is the backend configuration:</p>
  
  <pre><code>&lt;backend name="backend_1"&gt;
      &lt;class&gt;B4_1G&lt;/class&gt;
      &lt;options&gt;
          &lt;public&gt;true&lt;/public&gt;
          &lt;dynamic&gt;false&lt;/dynamic&gt;
      &lt;/options&gt;
  &lt;/backend&gt;
  </code></pre>
  
  <p>When the process is running (in default thread or parallel thread, i tried both) after a random amount i time i get</p>
  
  <pre><code>2013-09-13 18:52:14.677
  Process terminated because the backend took too long to shutdown.
  </code></pre>
  
  <p>I've looked around to find a solution, i read about the <a href="https://developers.google.com/appengine/docs/java/backends/#Java_Shutdown" rel="nofollow noreferrer">shutdown Hook for Backend instance</a>, which i implemented, but it seems not to be working.</p>
  
  <pre><code>LifecycleManager.getInstance().setShutdownHook(new ShutdownHook()
  {
      public void shutdown()
      {
          log().info("Shutting down...");
          LifecycleManager.getInstance().interruptAllRequests();
      }
  });
  </code></pre>
  
  <p>The log message is never shown, only the <code>Process terminated because...</code> message</p>
  
  <p>I also implemented the isShuttingDown check</p>
  
  <pre><code>LifecycleManager.getInstance().isShuttingDown();
  </code></pre>
  
  <p>In every cycle of my process, the first thing i check is if the backend is shutting down, but this flag is never true.</p>
  
  <p>The process is always "brutally" interrupted without any hook to control the shutdown (Maybe i can stop the operation saving some data for future resuming)</p>
  
  <p>I thought about an "out of memory" error, but i'm not storing any "big" object in memory. Also, at every cycle, the instance variables are set to NULL, forcing the release of the memory.</p>
  
  <p>Also, i'm expecting an error like this</p>
  
  <pre><code>Uncaught exception from servlet java.lang.OutOfMemoryError: Java heap space
  </code></pre>
  
  <p>if this is the problem</p>
  
  <p>Am i the only one experiencing this kind of problem?</p>
  
  <p>Already read <a href="https://stackoverflow.com/questions/12739411/gae-process-terminated-because-the-backend-took-too-long-to-shut-down-in-backen">this article</a>, but no solutions</p>