Main.java 854 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 {
  15. System.err.println("ERROR : unknown mutex type : " + args[0]);
  16. showUsage();
  17. return;
  18. }
  19. runExperiment();
  20. }
  21. private static void showUsage() {
  22. System.out.println("Usage : java Main <mutex_type>");
  23. System.out.println("Where <mutex_type> is one of D|A|H|P");
  24. }
  25. private static void runExperiment() {
  26. Task t0 = new Task("T0", 0, sharedMutex);
  27. Task t1 = new Task("T1", 1, sharedMutex);
  28. t0.describe();
  29. t1.describe();
  30. t0.start();
  31. t1.start();
  32. }
  33. }