awslabs / amazon-kinesis-client

Client library for Amazon Kinesis
Apache License 2.0
644 stars 467 forks source link

Problem shutting CWMetricsFactory down cleanly. #81

Closed rankinc closed 8 years ago

rankinc commented 8 years ago

I'm trying to use KCL 1.6.3, but I cannot stop the cw-metrics-publisher thread cleanly. Or more specifically, I can't tell when the cw-metrics-publisher thread has finished shutting down, so that I can then shutdown the AWSCloudWatch instance.

I am launching my Worker object in its own thread:

Future<?> task = executor.submit(worker);

This means that I can shutdown the worker by executing:

executor.shutdown();
worker.shutdown();

if (!executor.awaitTermination(... timeout ...)) {
    executor.shutdownNow();
}

However, this only guarantees that CWMetricsFactory.shutdown() has been invoked. It does not wait for CWPublisherRunnable<>.isShutdown() to become true. Nor do I have access to the CWMetricsFactory.publicationThread field so that I can poll its isAlive() method. (Not without hacking my way in using reflection, anyway).

I think the CWPublisherRunnable<> should finish executing before the Worker exits, and so I've tweaked CWMetricsFactory.shutdown() locally as follows:

    public void shutdown() {
        runnable.shutdown();
        try {
            publicationThread.join();
        } catch (InterruptedException e) {
            throw new AbortedException(e.getMessage(), e);
        }
    }

See pull request #81.

pfifer commented 8 years ago

PR #82 was released as part v1.6.5.