Skip to content

Use shutdown() instead of shutdownNow() when BoundedElasticScheduler call dispose. #3068

@ZejiaJiang

Description

@ZejiaJiang

I post hundreds of http request task with block() to scheduler. Sometimes I need to close my application and dispose the scheduler, then it'll throw interruptedException when each task get http response and notice the scheduler is disposed.

I'm wondering why not use shutdown() instead of shutdownNow() in dispose()?

@Override
public void dispose() {
BoundedServices services = BOUNDED_SERVICES.get(this);
if (services != SHUTDOWN && BOUNDED_SERVICES.compareAndSet(this, services, SHUTDOWN)) {
ScheduledExecutorService e = EVICTOR.getAndSet(this, null);
if (e != null) {
e.shutdownNow();
}
services.dispose();
}
}

Motivation

Currently when BoundedElasticScheduler call dispose(), it will halt all waiting tasks. Let waiting task finish not halt them toughly.

Desired solution

Use shutdown() instead of shutdownNow() in dispose().

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions