diff --git a/drools-core/src/main/java/org/drools/common/DefaultAgenda.java b/drools-core/src/main/java/org/drools/common/DefaultAgenda.java index e791c46efea..515f0adbd5f 100644 --- a/drools-core/src/main/java/org/drools/common/DefaultAgenda.java +++ b/drools-core/src/main/java/org/drools/common/DefaultAgenda.java @@ -264,6 +264,8 @@ public WorkingMemory getWorkingMemory() { * The item to schedule. */ public void scheduleItem(final ScheduledAgendaItem item, final InternalWorkingMemory wm) { + this.scheduledActivations.add( item ); + item.setEnqueued( true ); if( item.getPropagationContext().getReaderContext() == null ) { // this is not a serialization propagation, so schedule it // otherwise the timer will be correlated with this activation later during the @@ -272,8 +274,6 @@ public void scheduleItem(final ScheduledAgendaItem item, final InternalWorkingMe this, wm ); } - this.scheduledActivations.add( item ); - item.setEnqueued( true ); } @@ -439,7 +439,12 @@ private void addActivation(AgendaItem item, boolean notify) { final Timer timer = rule.getTimer(); if ( timer != null && item instanceof ScheduledAgendaItem ) { - scheduleItem( (ScheduledAgendaItem) item, + ScheduledAgendaItem sitem = (ScheduledAgendaItem) item; + if ( sitem.isEnqueued() ) { + // it's about to be re-added to scheduled list, so remove first + this.scheduledActivations.remove( sitem ); + } + scheduleItem( sitem, workingMemory ); } else { InternalAgendaGroup agendaGroup = (InternalAgendaGroup) this.getAgendaGroup( rule.getAgendaGroup() ); diff --git a/drools-core/src/main/java/org/drools/common/Scheduler.java b/drools-core/src/main/java/org/drools/common/Scheduler.java index 8f022a14f0d..979c608c7af 100644 --- a/drools-core/src/main/java/org/drools/common/Scheduler.java +++ b/drools-core/src/main/java/org/drools/common/Scheduler.java @@ -90,8 +90,10 @@ public void execute(JobContext ctx) { postpone(item, agenda); } - agenda.getScheduledActivationsLinkedList().remove( item ); - item.setEnqueued( false ); + if ( item.isEnqueued() ) { + agenda.getScheduledActivationsLinkedList().remove( item ); + item.setEnqueued( false ); + } } else { // the activation has been rescheduled, the Agenda would have set it's activated to false // so reset the activated to true here