我应该保持与Google云存储的开放连接吗

我应该保持与Google云存储的开放连接吗

本文介绍了我应该保持与Google云存储的开放连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要与Google Cloud Storage通信,请按照以下示例操作: https://developers.google.com/storage/docs/json_api/v1/json-api-java-samples

To communicate with Google Cloud Storage, I'm following this example: https://developers.google.com/storage/docs/json_api/v1/json-api-java-samples

我应该保持与云的开放连接吗?这会不会导致内存或资源问题?

Should I keep an open connection to the cloud? Wouldn't this cause memory or resources issues?

/** Global instance of the HTTP transport. */
private static HttpTransport httpTransport;

private static Storage client;

否则,我应该在每次获取/删除请求后关闭连接吗?最佳做法是什么?

Otherwise, should I close the connection after each get/delete request? what's the best practice?

我正在开发将在Linux上部署的应用程序.该应用程序将收到一个HTTP POST请求,其中包含要上传到云的文件.首次加载应用程序时,我将以下内容作为全局变量初始化:

I'm working on an application which will be deployed on Linux.The application will receive a HTTP POST request with a file to upload to the cloud.When the application is first loaded I initiate the following as global variables:

// Initialize the transport.
httpTransport = GoogleNetHttpTransport.newTrustedTransport();

// Initialize the data store factory.
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);

// Authorization.
Credential credential = authorize();

// Set up global Storage instance.
client = new Storage.Builder(httpTransport, JSON_FACTORY, credential)
    .setApplicationName(APPLICATION_NAME).build();

这是最佳做法吗?这种实现会导致我的内存/资源问题吗?

Is this the best practice? Will this implementation cause me memory/resources issues?

推荐答案

我认为您错过了Google的最佳做法文档.请参见将数据上传到Cloud Storage ,网址为 https://cloud.google.com/storage/docs/best-practices ,它将清除您的所有疑问.

I think you missed the best practice document from google. See Uploading data to Cloud Storage at https://cloud.google.com/storage/docs/best-practices which will clear your all doubts.

这篇关于我应该保持与Google云存储的开放连接吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 23:54