clebertsuconic commented on a change in pull request #3041: Two JIRAs around
Paging and AMQP
URL: https://github.com/apache/activemq-artemis/pull/3041#discussion_r396608747
##########
File path:
artemis-commons/src/main/java/org/apache/activemq/artemis/utils/actors/ProcessorBase.java
##########
@@ -99,45 +98,23 @@ public void shutdown(long timeout, TimeUnit unit) {
}
}
- /**
- * It will wait the current execution (if there is one) to finish
- * but will not complete any further executions
- */
+ /** It will shutdown the executor however it will not wait for finishing
tasks*/
public int shutdownNow(Consumer<? super T> onPendingItem) {
//alert anyone that has been requested (at least) an immediate shutdown
requestedForcedShutdown = true;
requestedShutdown = true;
- if (inHandler()) {
- stateUpdater.set(this, STATE_FORCED_SHUTDOWN);
- } else {
- //it could take a very long time depending on the current executing
task
- do {
- //alert the ExecutorTask (if is running) to just drain the current
backlog of tasks
- final int startState = stateUpdater.get(this);
- if (startState == STATE_FORCED_SHUTDOWN) {
- //another thread has completed a forced shutdown: let it to
manage the tasks cleanup
- break;
- }
- if (startState == STATE_RUNNING) {
- //wait 100 ms to avoid burning CPU while waiting and
- //give other threads a chance to make progress
- LockSupport.parkNanos(100_000_000L);
- }
- }
- while (!stateUpdater.compareAndSet(this, STATE_NOT_RUNNING,
STATE_FORCED_SHUTDOWN));
- //this could happen just one time: the forced shutdown state is the
last one and
- //can be set by just one caller.
- //As noted on the execute method there is a small chance that some
tasks would be enqueued
+ if (!inHandler()) {
+ flush(1, TimeUnit.SECONDS);
}
+
+ stateUpdater.set(this, STATE_FORCED_SHUTDOWN);
int pendingItems = 0;
- //there is a small chance that execute() could race with this cleanup:
the lock allow an all-or-nothing behaviour between them
- synchronized (tasks) {
- T item;
- while ((item = tasks.poll()) != null) {
- onPendingItem.accept(item);
- pendingItems++;
- }
+
+ T item;
+ while ((item = tasks.poll()) != null) {
Review comment:
I am removing the clear on onAddedTaskifNotRunning
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services