Index: DCWoRMS/branches/coolemall/src/schedframe/resources/units/ProcessingElements.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/units/ProcessingElements.java	(revision 1384)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/units/ProcessingElements.java	(revision 1392)
@@ -10,4 +10,5 @@
 import schedframe.resources.ResourceType;
 import schedframe.resources.computing.ComputingResource;
+import schedframe.scheduling.manager.tasks.JobRegistryImpl;
 
 public class ProcessingElements extends PEUnit implements List<ComputingResource> {
@@ -215,11 +216,11 @@
 		//allocate resources
 		if(delta > 0){
-				for(int i = 0; i < this.resources.size() && delta > 0; i++){
-					ComputingResource r = this.resources.get(i);
-					if(r.getStatus() == ResourceStatus.FREE || r.getStatus() == ResourceStatus.PENDING){
-						r.setStatus(ResourceStatus.BUSY);
-						delta--;
-					}
+			for(int i = 0; i < this.resources.size() && delta > 0; i++){
+				ComputingResource r = this.resources.get(i);
+				if(r.getStatus() == ResourceStatus.FREE || r.getStatus() == ResourceStatus.PENDING){
+					r.setStatus(ResourceStatus.BUSY);
+					delta--;
 				}
+			}
 		}
 		//free resources
@@ -228,6 +229,8 @@
 				ComputingResource r = this.resources.get(i);
 				if(r.getStatus() == ResourceStatus.BUSY){
-					r.setStatus(ResourceStatus.FREE);
-					delta++;
+					if(new JobRegistryImpl(r.getFullName()).getRunningTasks().size() == 0){
+						r.setStatus(ResourceStatus.FREE);
+						delta++;	
+					}
 				}
 			}
Index: DCWoRMS/branches/coolemall/src/schedframe/resources/computing/ComputingResource.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/resources/computing/ComputingResource.java	(revision 1374)
+++ DCWoRMS/branches/coolemall/src/schedframe/resources/computing/ComputingResource.java	(revision 1392)
@@ -16,5 +16,4 @@
 import schedframe.events.scheduling.SchedulingEvent;
 import schedframe.events.scheduling.SchedulingEventCommand;
-import schedframe.exceptions.ResourceException;
 import schedframe.resources.ResourceStatus;
 import schedframe.resources.ResourceType;
@@ -256,7 +255,11 @@
 				ResourceStateChangedEvent rscEvent = (ResourceStateChangedEvent) event;
 				EnergyEventType eeType = (EnergyEventType)rscEvent.getEventType();
-				scheduler.sendInternal(GridSimTags.SCHEDULE_NOW, DCWormsTags.RESOURCE_STATE_CHANGED, src);
+				//scheduler.sendInternal(GridSimTags.SCHEDULE_NOW, DCWormsTags.UPDATE_PROCESSING, src);
 				switch(eeType){
 				
+					case RESOURCE_UTILIZATION_CHANGED: {
+						scheduler.sendInternal(GridSimTags.SCHEDULE_NOW, DCWormsTags.UPDATE_PROCESSING, src);
+						break;
+					}
 					case FREQUENCY_CHANGED: {
 						scheduler.sendInternal(GridSimTags.SCHEDULE_NOW, DCWormsTags.UPDATE_PROCESSING, src);
@@ -310,4 +313,3 @@
 	}
 
-
 }
Index: DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 1385)
+++ DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java	(revision 1392)
@@ -353,5 +353,5 @@
 		
 		PEUnit peUnit = (PEUnit)choosenResources.get(StandardResourceUnitName.PE);
-		updateComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec);
+		updateComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
 		
 
@@ -435,4 +435,6 @@
 		log.debug(execTask.getJobId() + "_" + execTask.getId() + " finished execution on " + new DateTime());
 		log.info(DCWormsConstants.USAGE_MEASURE_NAME + ": " + calculateTotalLoad());
+		
+		updateComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec);
 	}
 	
@@ -702,5 +704,5 @@
 	
 	
-	public void saveExecutionHistory(Executable exec, double completionPercentage, double estimatedDuration){
+	private void saveExecutionHistory(Executable exec, double completionPercentage, double estimatedDuration){
 
 		ExecutionHistoryItem execHistoryItem = new ExecutionHistoryItem(new DateTime());
@@ -711,4 +713,18 @@
 		exec.addExecHistory(execHistoryItem);
 		
+	}
+	
+	public boolean allocateResources(Executable exec, Map<ResourceUnitName, ResourceUnit> choosenResources, boolean exclusive){
+		boolean allocationStatus = getAllocationManager().allocateResources(choosenResources, exclusive);
+		if(allocationStatus){
+			ResourceHistoryItem resourceHistoryItem = new ResourceHistoryItem(choosenResources);
+			exec.addAllocatedResources(resourceHistoryItem);
+			saveResourceHistory(exec);
+			return true;
+		}
+		return false;
+	}
+	
+	private void saveResourceHistory(Executable exec){
 		ProcessingElements pes = (ProcessingElements) exec.getAllocatedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE);
 		for (ComputingResource resource : pes) {
@@ -735,12 +751,3 @@
 	}
 	
-	public boolean allocateResources(Executable exec, Map<ResourceUnitName, ResourceUnit> choosenResources, boolean exclusive){
-		boolean allocationStatus = getAllocationManager().allocateResources(choosenResources, exclusive);
-		if(allocationStatus){
-			ResourceHistoryItem resourceHistoryItem = new ResourceHistoryItem(choosenResources);
-			exec.addAllocatedResources(resourceHistoryItem);
-			return true;
-		}
-		return false;
-	}
 }
Index: DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/resources/LocalResourceManager.java
===================================================================
--- DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/resources/LocalResourceManager.java	(revision 1377)
+++ DCWoRMS/branches/coolemall/src/schedframe/scheduling/manager/resources/LocalResourceManager.java	(revision 1392)
@@ -310,4 +310,5 @@
 					for(ComputingResource cr: pe){
 						if(cr.getStatus().equals(ResourceStatus.BUSY)){
+							freeResources(resources, true);
 							return false;
 						}
