我正在开发简单的调查服务。我在backend instance收集统计信息,并每小时将其转储到datastore。我为我的后端实例注册了shutdown hook,以便在最后一小时内收集的数据不会丢失。我还使用缓存来存储我的一些数据。
奇怪地呼叫MemcacheService.get()中的LifecycleManager.ShutdownHook.shutdown()会导致InterruptedException被抛出。这是完整的调用堆栈:
com.google.appengine.api.memcache.MemcacheServiceException: Unexpected failure
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:29)
at com.google.appengine.api.memcache.MemcacheServiceImpl.getAll(MemcacheServiceImpl.java:59)
at HitsHelper$LifetimeStats.getCachedStats(HitsHelper.java:51)
at HitsHelper$LifetimeStats.update(HitsHelper.java:28)
at HitsHelper.shutdown(HitsHelper.java:271)
at com.google.appengine.api.LifecycleManager.beginShutdown(LifecycleManager.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.appengine.tools.development.BackendServers$ServerWrapper.triggerLifecycleShutdownHook(BackendServers.java:890)
at com.google.appengine.tools.development.BackendServers$ServerWrapper.shutdown(BackendServers.java:796)
at com.google.appengine.tools.development.BackendServers.stopBackend(BackendServers.java:242)
at com.google.apphosting.utils.servlet.ServersServlet$1.run(ServersServlet.java:97)
at java.security.AccessController.doPrivileged(Native Method)
at com.google.apphosting.utils.servlet.ServersServlet.doPost(ServersServlet.java:93)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:351)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1302)
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:227)
at java.util.concurrent.FutureTask.get(FutureTask.java:91)
at com.google.appengine.tools.development.ApiProxyLocalImpl$PrivilegedApiAction$1.get(ApiProxyLocalImpl.java:288)
at com.google.appengine.tools.development.ApiProxyLocalImpl$PrivilegedApiAction$1.get(ApiProxyLocalImpl.java:250)
at com.google.appengine.tools.development.TimedFuture.get(TimedFuture.java:41)
at com.google.appengine.api.utils.FutureWrapper.get(FutureWrapper.java:74)
at com.google.appengine.api.memcache.MemcacheServiceImpl.quietGet(MemcacheServiceImpl.java:27)
... 46 more
有解决方法吗?我真的需要在我的实例死之前更新缓存。
谢谢!
答案 0 :(得分:0)
正在观察时,在关机期间进行的RPC调用可能会被中断。您不应该依赖于被调用的关闭处理程序来保存重要数据 - 您应该基于每个请求执行此操作。
答案 1 :(得分:0)
我刚刚意识到我在shutdown()方法的开头有LifecycleManager.interruptAllRequests()。它将所有线程置于中断状态。那是例外的原因。