java 如何关闭 AWS S3 客户端连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26866739/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I close an AWS S3 client connection
提问by visc
What is the protocol for closing an aws s3 client connection?
关闭 aws s3 客户端连接的协议是什么?
@Override
public boolean connect() {
if (connected)
return false;
else
s3Client = new AmazonS3Client(credentials);
return true;
}
@Override
public boolean diconnect() {
// what should take place here?
return false;
}
回答by Matt
You don't need to close a 'connection", as there's no such thing as a continuous connection to S3 when using AmazonS3Client.
您不需要关闭“连接”,因为在使用 AmazonS3Client 时不存在与 S3 的持续连接。
The AWS java SDK send REST requests to S3, where REST is stateless, for each REST request, it will be signed with the user credentials information, so it doesn't need a long connection(such as something like session).
AWS java SDK 向 S3 发送 REST 请求,其中 REST 是无状态的,对于每个 REST 请求,它将使用用户凭据信息进行签名,因此它不需要长连接(例如 session 之类的东西)。
回答by David Weinberg
In the documentation there is an optional method called 'shutdown'
在文档中有一个可选的方法叫做' shutdown'
Shuts down this client object, releasing any resources that might be held open. This is an optional method, and callers are not expected to call it, but can if they want to explicitly release any open resources. Once a client has been shutdown, it should not be used to make any more requests.
关闭此客户端对象,释放任何可能保持打开状态的资源。这是一个可选方法,调用者不会调用它,但是如果他们想显式释放任何打开的资源,可以调用它。客户端关闭后,不应再使用它来发出任何请求。
For example
例如
@Override
public boolean disconnect() {
s3Client.shutdown()
return false;
}