Index: proiecte/ptvs/src/vnsim/core/Engine.java
===================================================================
--- proiecte/ptvs/src/vnsim/core/Engine.java	(revision 81)
+++ proiecte/ptvs/src/vnsim/core/Engine.java	(revision 87)
@@ -16,4 +16,6 @@
 import java.util.ListIterator;
 import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import vnsim.applications.adaptiveTL.IntersectionCarRecord;
@@ -85,4 +87,6 @@
 public class Engine {
 	
+	public static int numThreads;
+	
 	/* EZCab - file informations about the client */
 	public static BufferedWriter bwClient, bwCab;
@@ -212,4 +216,7 @@
 			
 		ArrayList<Intersection> intersectii = map.allIntersections;
+		
+		numThreads=intersectii.size();
+		
 		for(int q=0;q<intersectii.size();q++){
 			System.out.println("intersectia "+q+": "+" nume: "+intersectii.get(q).toString()+" "+intersectii.get(q).getMapPoint());
@@ -480,4 +487,16 @@
 	long lastTime = -1;
 	
+	
+	/////////////////////////////////////// thread pool with Executors ////////////////////
+	/**
+	 * PTVS Project
+	 */
+	public ExecutorService executor[];
+	
+	public void start(Event e, int i) throws IOException {
+	    
+	      executor[i].submit(new EventProcessingThread(e, this));
+	  }
+	
 	////////////////////////////////////// step ///////////////////////////////////////////////////////////
 	/**
@@ -487,4 +506,10 @@
 	
 	static int cnt = 0;
+	
+	/**
+	 * PTVS
+	 */
+	int dimens = 0;
+	int eventTime=0;
 	
 	public void step() {
@@ -650,9 +675,17 @@
 		Map map = Globals.map;
 		ArrayList<Intersection> intersectii = map.allIntersections;
-		int numThreads=intersectii.size();
+		numThreads=intersectii.size();
 		
 		//v1 - noThreads = noIntersections
-		Runnable processingThreads[] = new Runnable[numThreads];
+		//Runnable processingThreads[] = new Runnable[numThreads];
 		//
+		//System.out.println("numThreads:"+numThreads);
+		
+		executor=new ExecutorService[numThreads];
+		
+		for(int i=0;i<numThreads;i++){
+			executor[i] = Executors.newFixedThreadPool(1); // un singur thread e mereu refolosit pt fiecare intersectie.. ar putea fi mai multe
+		}
+		 
 		
 		while (true) {
@@ -665,6 +698,18 @@
 			// extrag un eveniment din coada !!!!! acum doar il extrag.. cand intru in playEvent il si scot cu remove(0)
 			Event e = (Event) eventQueue.get(0);
+			
+			/*if (e.getTime() == crtTime) {
+				System.out.println("----||||--------->> e.getTime() == crtTime== "+crtTime);
+				eventTime = crtTime;
+			}*/
+			
 			if (e == null) continue;
-			System.out.println("\n----------- number of events in the queue:"+eventQueue.size() );
+			
+			if(dimens!=eventQueue.size()){
+				
+				System.out.println("\n----------- number of events in the queue:" +eventQueue.size());
+				dimens = eventQueue.size();
+			}
+			
 			
 			/**
@@ -677,5 +722,9 @@
 		
 			if((e instanceof SendEvent) || (e instanceof ReceiveEvent)){
-				e = (Event)eventQueue.remove(0);
+				
+				synchronized (eventQueue) {
+					e = (Event)eventQueue.remove(0);
+				}
+				
 				/**
 				 * PTVS Project
@@ -720,6 +769,4 @@
 				 */
 				
-				// nu e bine cu apelul lui run pt ca practic nu se porneste un thread nou ci 
-				// se apeleaza metoda run ca orice alta metoda dintr-o clasa, executia este secventiala..
 				
 				if (e.getTime() == crtTime) {
@@ -728,14 +775,24 @@
 						
 							System.out.print("SendEvent: ");
-							processingThreads[indexClosestIntersection] = new SendEventProcessingThread(e,this);
+														
+							//processingThreads[indexClosestIntersection] = new SendEventProcessingThread(e,this);
 						}
 					else {					
 							System.out.print("ReceiveEvent: ");
-							processingThreads[indexClosestIntersection] = new ReceiveEventProcessingThread(e,this);
+														
+							//processingThreads[indexClosestIntersection] = new ReceiveEventProcessingThread(e,this);
 						}
 					
 					System.out.println("Processing thread "+indexClosestIntersection+" from intersection "+intersectii.get(indexClosestIntersection));
-					//processingThreads[indexClosestIntersection].start();// cu start nu merge ... why????
-					new Thread(processingThreads[indexClosestIntersection]).start();
+					
+					try {
+						start(e,indexClosestIntersection);
+						
+					} catch (IOException e1) {
+						
+						e1.printStackTrace();
+					}
+					
+					//new Thread(processingThreads[indexClosestIntersection]).start();
 					cnt++;
 				}
