GAE,Java 11 Flex环境,无法创建关闭挂钩

时间:2019-01-20 13:14:48

标签: google-app-engine google-cloud-platform gcloud

我拥有可在自定义运行时(Java 11)的flex环境中部署的GAE,一切正常。 添加关闭挂钩时,我会因以下异常而失败:

java.lang.NullPointerException: Operation not allowed in a thread that is neither the original request thread nor a thread created by ThreadManager

完整跟踪:

Unexpected exception occurred invoking async method: public void com.xyz.hooks.shutdown.googleAppEngine.GoogleAppEngineShutDownHook.registerHook()
java.lang.NullPointerException: Operation not allowed in a thread that is neither the original request thread nor a thread created by ThreadManager
    at com.google.appengine.api.LifecycleManager.currentAppVersionId(LifecycleManager.java:92)
    at com.google.appengine.api.LifecycleManager.setShutdownHook(LifecycleManager.java:40)
    at com.xyz.hooks.shutdown.googleAppEngine.GoogleAppEngineShutDownHook.registerHook(GoogleAppEngineShutDownHook.java:29)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor.lambda$invoke$0(AsyncExecutionInterceptor.java:115)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:834

我的代码:

  LifecycleManager.getInstance().setShutdownHook(() -> {
            shutdownService.flushAll();
        });

0 个答案:

没有答案