简体   繁体   English

如何避免Google App Engine不支持Runtime.addShutdownHook

[英]how to avoid Google App Engine does not support Runtime.addShutdownHook

I run this java code on google app engine (java7) 我在Google App Engine(java7)上运行此Java代码

and i get an error, but i'm not sure what does it mean and how to avoid it? 我得到一个错误,但是我不确定这是什么意思以及如何避免它?

        final TopicName topicName = pubSubFactory.createOrGetTopic(SpreadSheetConfig.s.TOPIC_NAME_ADD_PARTNER_REQUEST);
        CustomPublisher customPublisher = pubSubFactory.createPublisher(topicName);
        PublisherCallbackWithLog publisherCallback = new PublisherCallbackWithLog<String>();

        for (WazeSdkPartner.WazeSdkRequest wazeSdkRequest : wazeSdkRequestsList.getRequestList()) {
            customPublisher.publish(wazeSdkRequest, publisherCallback);
        }

and

public <T extends MessageLite> ApiFuture<String> publish(final T message, final ApiFutureCallback<T> futureCallback) throws Exception {
    final PubsubMessage      pubsubMessage   = PubsubMessage.newBuilder().setData(message.toByteString()).build();
    final ApiFuture<String>  messageIdFuture = publisher.publish(pubsubMessage);

    if ( futureCallback != null ) {
        ApiFutures.addCallback(messageIdFuture, (ApiFutureCallback) futureCallback);
    }

    return messageIdFuture;
}

error: Google App Engine does not support Runtime.addShutdownHook 错误:Google App Engine不支持Runtime.addShutdownHook

/
java.lang.RuntimeException: java.lang.SecurityException: Google App Engine does not support Runtime.addShutdownHook
    at com.waze.sdkService.servlets.SdkPollerServlet.publishAddPartnersRequests(SdkPollerServlet.java:96)
    at com.waze.sdkService.servlets.SdkPollerServlet.publishRequestsIfNewPartners(SdkPollerServlet.java:72)
    at com.waze.sdkService.servlets.SdkPollerServlet.doGet(SdkPollerServlet.java:63)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

You are seeing that error because Google Cloud PubSub uses gRPC as transport layer. 您正在看到该错误,因为Google Cloud PubSub使用gRPC作为传输层。 In particular, it uses a ManagedChannel and a ScheduledExecutorService for making calls (both provided as a ChannelAndExecutor pair). 特别是,它使用ManagedChannelScheduledExecutorService进行呼叫(均作为ChannelAndExecutor对提供)。 The executor service exits when the application is complete, and it does so by using daemon threads and adding a shutdown hook to wait for their completion. 执行程序服务在应用程序完成时退出,它通过使用守护程序线程并添加关闭挂钩来等待它们完成而退出。

However, gRPC is not supported by App Engine Standard using the Java 7 runtime. 但是,使用Java 7运行时的App Engine Standard不支持gRPC Java 8 supports gRPC , but it looks like there are no plans to support it also on Java 7 (see this google-cloud-java GitHub issue ). Java 8支持gRPC ,但似乎也没有计划在Java 7上也支持它(请参阅google-cloud-java GitHub问题 )。

To specify the Java 8 runtime for your application, just add this line to your appengine-web.xml file: 要为您的应用程序指定Java 8运行时,只需appengine-web.xml下行添加到appengine-web.xml文件中:

<runtime>java8</runtime>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Engine不支持vision api Runtime.addShutdownHook错误 - Google App Engine does not support vision api Runtime.addShutdownHook error Stage.setOnCloseRequest()和Runtime.addShutdownHook()有什么区别? - What are the differences between Stage.setOnCloseRequest() and Runtime.addShutdownHook()? Google App Engine 是否支持 Java 8? - Does Google App Engine support Java 8? Google App Engine数据存储区不支持运算符+ - Google App Engine datastore does not support operator + Google App Engine是否支持使用Spring @Async? - Does Google App Engine support using Spring @Async? Flying Saucer库是否支持Google App-Engine? - Does Flying Saucer library support for Google App-Engine? Google App Engine Java是否支持Eclipse中的热部署? - Does Google App Engine Java support Hot Deployment in Eclipse? 连接到Google Compute Engine代理服务器时,“ Google App Engine不支持使用代理”错误 - 'Google App Engine does not support the use of proxies' error when connecting to Google Compute Engine proxy server Google App Engine沙盒如何运作? - How does Google App Engine sandbox work? 如何在Google App Engine(Java)中启用会话支持? - How do I enable session support in Google App Engine (Java)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM