<aws-context:context-credentials>
<aws-context:simple-credentials access-key="${s3.key}" secret-key="${s3.secret}"/>
</aws-context:context-credentials>
<aws-context:context-resource-loader/>
ObjectMetadata meta = new ObjectMetadata();
meta.setContentType(contentType);
meta.setContentLength(bytes.length);
try (ByteArrayInputStream bis = new ByteArrayInputStream(bytes)) {
TransferManager transferManager = new TransferManager(this.amazonS3);
Upload upload = transferManager.upload(BUCKET, fileName, bis, meta);
UploadResult result = upload.waitForUploadResult(); // here is an exception!
}
PutObjectRequest request = new PutObjectRequest(BUCKET, fileName, bis, meta);
request.setCannedAcl(CannedAccessControlList.PublicRead);
amazonS3.putObject(request);
com.amazonaws.AmazonClientException: Unable to complete transfer: Connection pool shut down
at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.unwrapExecutionException(AbstractTransfer.java:277)
at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.rethrowExecutionException(AbstractTransfer.java:261)
at com.amazonaws.services.s3.transfer.internal.UploadImpl.waitForUploadResult(UploadImpl.java:66)
...
Caused by: java.lang.IllegalStateException: Connection pool shut down
at org.apache.http.util.Asserts.check(Asserts.java:34)
at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:184)
at org.apache.http.pool.AbstractConnPool.lease(AbstractConnPool.java:217)
at org.apache.http.impl.conn.PoolingClientConnectionManager.requestConnection(PoolingClientConnectionManager.java:186)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.amazonaws.http.conn.ClientConnectionManagerFactory$Handler.invoke(ClientConnectionManagerFactory.java:72)
at com.amazonaws.http.conn.$Proxy11.requestConnection(Unknown Source)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:416)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.amazonaws.http.AmazonHttpClient.executeOneRequest(AmazonHttpClient.java:749)
at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:505)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:317)
at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:3595)
at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1382)
at com.amazonaws.services.s3.transfer.internal.UploadCallable.uploadInOneChunk(UploadCallable.java:131)
at com.amazonaws.services.s3.transfer.internal.UploadCallable.call(UploadCallable.java:123)
at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:139)
at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:47)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
... 1 more
看来PoolingClientConnectionManager
是从Apache httpclient 4.5.2
到达这里的,我也在我的项目中使用它
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
但这只是一个假设。问题可能出在别的地方。有什么想法吗?
我找到了解决办法,但它需要完全更改AmazonS3
配置的方法:
<bean id="basicAwsCredentials" class="com.amazonaws.auth.BasicAWSCredentials">
<constructor-arg name="accessKey" value="${s3.key}"/>
<constructor-arg name="secretKey" value="${s3.secret}"/>
</bean>
<bean id="amazonS3Client" class="com.amazonaws.services.s3.AmazonS3Client">
<constructor-arg name="awsCredentials" ref="basicAwsCredentials"/>
</bean>
在这样的配置中,一切都像一个魅力。
因此,看起来Spring的aws-context
工作错误,或者我错误地使用了它。但是在以前的配置中,autowiredAmazons3
实例不是null
,所以我不知道它不能正常工作的原因。
我也尝试了这个解决方案,即显式地创建两个bean BasicAWSCredentials和AmazonS3Client,并相应地配置它,但仍然显示了相同的错误。
在为了使用多线程而修改了一个服务方法之后,我发现如果不止一个用户多次尝试请求页面(并调用服务方法),服务器就会抛出“无法连接,池耗尽”异常。让我提供一个我的服务类的例子。 我已经在这个问题上挣扎了一个多星期,我找不到解决方案。我不太明白Grails如何与会话、连接和事务一起工作。我的猜测是跟随。当调用ConvertDocumentToJSON时,它从池中获取连接(4个用户,每个用户25个线程=10
问题内容: 我正在阅读有关此问题,但仍然没有找到解决方案。我注意到有时,我的应用会引发此错误: 我有一个使用此方法的文件,以获取其实例: 然后,我有类似这样的方法(它在发生该错误的行中崩溃)。它几乎从不崩溃,但有时会崩溃。 就这样,在我使用的所有方法中: 然后关闭游标和数据库。在这种情况下,该错误被抛出该行: 我不明白为什么如果我之前打电话,错误提示数据库已关闭。请支持!谢谢 :) 问题答案: 去
我使用了SQLiteDataBaseHelper类,其getInstance方法更改为synchronize. 作为此答案,但仍然存在问题not fixed。
我不明白为什么如果我之前调用,错误会说数据库是关闭的。请支持!谢谢:)
我试着用谷歌搜索了很多个小时,但没有结果。请帮我把它修好。任何帮助都将不胜感激。谢谢!