Skip to content

Gracefully shutting down the AmazonsS3 ExecutorService #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/scala/s3/s3.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import scala.collection.JavaConverters._
import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.util.Try

import java.util.concurrent.{Executors, ExecutorService, ThreadFactory}
import java.util.concurrent.{TimeUnit, Executors, ExecutorService, ThreadFactory}
import java.util.concurrent.atomic.AtomicLong

import com.amazonaws.{AmazonWebServiceRequest, ClientConfiguration}
Expand Down Expand Up @@ -183,13 +183,16 @@ class AmazonS3ScalaClient(
def getExecutorsService(): ExecutorService = executorService

/**
* Shutdown the executor service.
* Attempt to shutdown the executor service gracefully, and if it takes longer than 30 seconds issues a ShutdownNow command which interrupts the sleeping com.amazonaws.http.IdleConnectionReaper.
*
* @see [[http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/AmazonWebServiceClient.html#shutdown() AmazonWebServiceClient.shutdown()]]
*/
def shutdown(): Unit = {
client.shutdown()
executorService.shutdownNow()
executorService.shutdown()
if (!executorService.awaitTermination(30, TimeUnit.SECONDS)) {
executorService.shutdownNow()
}
()
}

Expand Down