wod*_*dle 1 java amazon-web-services
我发现创建一个AmazonS3Client意味着我的进程即使在什么都不做的时候也会挂起.我正在进行文件上传,但我已将其修改为此.
当我运行以下代码(带有工作凭据)时,它会输出"Simple is finished",但该过程不会退出,直到最终maven:exec告诉我:
Simple is finished
[WARNING] thread Thread[java-sdk-http-connection-reaper,5,Simple] was interrupted but is still alive after waiting at least 15000msecs
[WARNING] thread Thread[java-sdk-http-connection-reaper,5,Simple] will linger despite being asked to die via interruption
[WARNING] NOTE: 1 thread(s) did not finish despite being asked to via interruption. This is not a problem with exec:java, it is a problem with the running code. Although not serious, it should be remedied.
[WARNING] Couldn't destroy threadgroup org.codehaus.mojo.exec.ExecJavaMojo$IsolatedThreadGroup[name=Simple,maxpri=10]
java.lang.IllegalThreadStateException
Run Code Online (Sandbox Code Playgroud)
代码:
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
public class Simple {
private static String accessKey = "XXX";
private static String secretKey = "ZZZ";
public static void main(String[] args) {
AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3 s3client = new AmazonS3Client(credentials);
System.out.println("Simple is finished");
}
}
Run Code Online (Sandbox Code Playgroud)
它应该像这样工作吗?有没有办法杀掉它?
编辑:添加版本信息:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.33</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
其中任何一个似乎都有效:
((AmazonS3Client) s3client).shutdown();
Run Code Online (Sandbox Code Playgroud)
要么
try {
com.amazonaws.http.IdleConnectionReaper.shutdown();
} catch (Throwable t) {
// etc
}
Run Code Online (Sandbox Code Playgroud)
虽然我不确定它们是多么正确.
| 归档时间: |
|
| 查看次数: |
1866 次 |
| 最近记录: |