Skip to content

Add async stop notification API to DefaultMessageListenerContainer [SPR-4414] #9092

Closed
@spring-projects-issues

Description

@spring-projects-issues

Ben Rowlands opened SPR-4414 and commented

DMLC has 2 options to quiesce the containers threads.

  • Stop(): notifies the threads to stop
  • Shutdown(): notifies the threads to stop and then waits for all the threads to stop.

We need to wait for all the threads to stop so we can then shutdown dependent components in the application (we don't want to shut these down until all message processing is complete). So we used shutdown(), however after shutdown the container can't be re-started!. So we use stop() but then we don't know when the stop is complete.

A simple option would be adding a stopAndWait() API that would block the calling thread until the containers threads are stopped. But we'd like to stop all our containers (we may have >10 in the application) concurrently. A nice way to do this is to give a callback to stop() to be invoked on completion.

// notifies the containers threads to stop, invokes the callback when all threads are done.
void stop( CompletionCallback completionCallback )

Where CompletionCallback is (could use Runnable?):

interface CompletionCallback
{
public void complete();
}

We can then await stopping something like:

final CountDownLatch latch = new CountDownLatch( containers.size )
CompletionCallback callback = new CompletionCallback() {
void complete() { latch.countDown(); }
};

for( DMLC container : containers ) {
container.stop( callback );
}

latch.await();

If this API doesn't seem generally useful would it be possible to provide a subclass hook to allow this as the monitor & counters are not visible (looks like something that could be easily refactored out of doShutdown()).

Thanks


Affects: 2.5.1

Issue Links:

Metadata

Metadata

Assignees

Labels

in: messagingIssues in messaging modules (jms, messaging)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions