[英]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). 特别是,它使用
ManagedChannel
和ScheduledExecutorService
进行呼叫(均作为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.