/** * @author Octavian Udrea * * A sample simulation. Please note that if you have a deadlock, you may never reach the analysis phase. */ public class Simulation { public static void main(String[] args) { Bridge b = new Bridge("B",10,2); Car c1 = new Car("CA",3,10,2,0,b); Car c2 = new Car("CB",2,10,1,1,b); Car c3 = new Car("CC",5,10,3,1,b); Car c4 = new Car("CD",10,10,2,1,b); Car c5 = new Car("CE",10,10,2,0,b); Ship s1 = new Ship("SA",1,7,3,b); Ship s2 = new Ship("SB",2,8,2,b); long m = System.currentTimeMillis(); b.start(); c1.start(); c2.start(); c3.start(); c4.start(); c5.start(); s1.start(); s2.start(); try { c1.join(); c2.join(); c3.join(); c4.join(); c5.join(); s1.join(); s2.join(); } catch(InterruptedException e) {} System.out.println("Simulation done in " + (System.currentTimeMillis() - m) + " miliseconds..."); Analyzer a = new Analyzer(EventPrinter.out.getLog()); System.out.println("=========================================================================="); System.out.println("Starting analysis..."); int x = a.analyze(); System.out.println("" + x + " problem(s) found."); System.exit(1); // just kill the Bridge thread } }