- Timestamp:
- Jan 10, 2010, 9:17:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
proiecte/ptvs/src/vnsim/core/Engine.java
r81 r87 16 16 import java.util.ListIterator; 17 17 import java.util.Random; 18 import java.util.concurrent.ExecutorService; 19 import java.util.concurrent.Executors; 18 20 19 21 import vnsim.applications.adaptiveTL.IntersectionCarRecord; … … 85 87 public class Engine { 86 88 89 public static int numThreads; 90 87 91 /* EZCab - file informations about the client */ 88 92 public static BufferedWriter bwClient, bwCab; … … 212 216 213 217 ArrayList<Intersection> intersectii = map.allIntersections; 218 219 numThreads=intersectii.size(); 220 214 221 for(int q=0;q<intersectii.size();q++){ 215 222 System.out.println("intersectia "+q+": "+" nume: "+intersectii.get(q).toString()+" "+intersectii.get(q).getMapPoint()); … … 480 487 long lastTime = -1; 481 488 489 490 /////////////////////////////////////// thread pool with Executors //////////////////// 491 /** 492 * PTVS Project 493 */ 494 public ExecutorService executor[]; 495 496 public void start(Event e, int i) throws IOException { 497 498 executor[i].submit(new EventProcessingThread(e, this)); 499 } 500 482 501 ////////////////////////////////////// step /////////////////////////////////////////////////////////// 483 502 /** … … 487 506 488 507 static int cnt = 0; 508 509 /** 510 * PTVS 511 */ 512 int dimens = 0; 513 int eventTime=0; 489 514 490 515 public void step() { … … 650 675 Map map = Globals.map; 651 676 ArrayList<Intersection> intersectii = map.allIntersections; 652 intnumThreads=intersectii.size();677 numThreads=intersectii.size(); 653 678 654 679 //v1 - noThreads = noIntersections 655 Runnable processingThreads[] = new Runnable[numThreads];680 //Runnable processingThreads[] = new Runnable[numThreads]; 656 681 // 682 //System.out.println("numThreads:"+numThreads); 683 684 executor=new ExecutorService[numThreads]; 685 686 for(int i=0;i<numThreads;i++){ 687 executor[i] = Executors.newFixedThreadPool(1); // un singur thread e mereu refolosit pt fiecare intersectie.. ar putea fi mai multe 688 } 689 657 690 658 691 while (true) { … … 665 698 // extrag un eveniment din coada !!!!! acum doar il extrag.. cand intru in playEvent il si scot cu remove(0) 666 699 Event e = (Event) eventQueue.get(0); 700 701 /*if (e.getTime() == crtTime) { 702 System.out.println("----||||--------->> e.getTime() == crtTime== "+crtTime); 703 eventTime = crtTime; 704 }*/ 705 667 706 if (e == null) continue; 668 System.out.println("\n----------- number of events in the queue:"+eventQueue.size() ); 707 708 if(dimens!=eventQueue.size()){ 709 710 System.out.println("\n----------- number of events in the queue:" +eventQueue.size()); 711 dimens = eventQueue.size(); 712 } 713 669 714 670 715 /** … … 677 722 678 723 if((e instanceof SendEvent) || (e instanceof ReceiveEvent)){ 679 e = (Event)eventQueue.remove(0); 724 725 synchronized (eventQueue) { 726 e = (Event)eventQueue.remove(0); 727 } 728 680 729 /** 681 730 * PTVS Project … … 720 769 */ 721 770 722 // nu e bine cu apelul lui run pt ca practic nu se porneste un thread nou ci723 // se apeleaza metoda run ca orice alta metoda dintr-o clasa, executia este secventiala..724 771 725 772 if (e.getTime() == crtTime) { … … 728 775 729 776 System.out.print("SendEvent: "); 730 processingThreads[indexClosestIntersection] = new SendEventProcessingThread(e,this); 777 778 //processingThreads[indexClosestIntersection] = new SendEventProcessingThread(e,this); 731 779 } 732 780 else { 733 781 System.out.print("ReceiveEvent: "); 734 processingThreads[indexClosestIntersection] = new ReceiveEventProcessingThread(e,this); 782 783 //processingThreads[indexClosestIntersection] = new ReceiveEventProcessingThread(e,this); 735 784 } 736 785 737 786 System.out.println("Processing thread "+indexClosestIntersection+" from intersection "+intersectii.get(indexClosestIntersection)); 738 //processingThreads[indexClosestIntersection].start();// cu start nu merge ... why???? 739 new Thread(processingThreads[indexClosestIntersection]).start(); 787 788 try { 789 start(e,indexClosestIntersection); 790 791 } catch (IOException e1) { 792 793 e1.printStackTrace(); 794 } 795 796 //new Thread(processingThreads[indexClosestIntersection]).start(); 740 797 cnt++; 741 798 }
Note: See TracChangeset
for help on using the changeset viewer.