Main.java 949 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. class Main {
  2. static Mutex sharedMutex;
  3. public static void main(String args[]){
  4. System.out.println("Start thread lab");
  5. if (args.length != 1) {
  6. System.err.println("ERROR : incorrect argument.");
  7. showUsage();
  8. return;
  9. }
  10. if (args[0].equals("D"))
  11. sharedMutex = new MutexTypeD();
  12. else if (args[0].equals("H"))
  13. sharedMutex = new MutexTypeH();
  14. else if (args[0].equals("N"))
  15. sharedMutex = new MutexTypeN();
  16. else {
  17. System.err.println("ERROR : unknown mutex type : " + args[0]);
  18. showUsage();
  19. return;
  20. }
  21. runExperiment();
  22. }
  23. private static void showUsage() {
  24. System.out.println("Usage : java Main <mutex_type>");
  25. System.out.println("Where <mutex_type> is one of N|D|A|H|P");
  26. }
  27. private static void runExperiment() {
  28. Task t0 = new Task("T0", 0, sharedMutex);
  29. Task t1 = new Task("T1", 1, sharedMutex);
  30. t0.describe();
  31. t1.describe();
  32. sharedMutex.describe();
  33. t0.start();
  34. t1.start();
  35. }
  36. }