TD1: Cleanup the exo1 code.
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 6 Mar 2018 17:20:11 +0000 (18:20 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Tue, 6 Mar 2018 17:20:11 +0000 (18:20 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
TD1/exo2/Main.java
TD1/exo2/Makefile
TD1/exo2/ThreadJob.java [moved from TD1/exo2/ExThread.java with 74% similarity]

index d28e6b3b5402f0b1b8b8cc9dcc24813ad6e13de7..9bab323cffdde5386461d54e873df94a5b143bcb 100644 (file)
@@ -1,22 +1,21 @@
 class Main {
 
      public static void main(String[] args) {
-         final int THREADS_NUMBER = 3;
-         ExThread threadArray[] = new ExThread[THREADS_NUMBER];
+         final int THREADS_NUMBER = 3;;
          Thread t[] = new Thread[THREADS_NUMBER];
 
-         for (int i = 0; i < threadArray.length; i++) {
-             threadArray[i] = new ExThread(String.valueOf(i));
-             t[i] = new Thread(threadArray[i]);
+         for (int i = 0; i < t.length; i++) {
+             ThreadJob threadJob = new ThreadJob(String.valueOf(i));
+             t[i] = new Thread(threadJob);
              t[i].start();
          }
 
-         for (int i = 0; i < threadArray.length; i++) {
+         for (int i = 0; i < t.length; i++) {
             try {
                 t[i].join();
             }
             catch (InterruptedException e) {
-             // this part is executed when an exception (in this example InterruptedException) occurs
+                // this part is executed when an exception (in this example InterruptedException) occurs
             }
         }
         System.out.println("Threads execution finished");
index e589d5db0c6e84563b91eadb9b5ab79ad2d8db07..648bd3858bbe4c281b8994b6168ebf7b632c8f48 100644 (file)
@@ -46,7 +46,7 @@ JVM = java
 # NAME = Camilo        Juan
 
 CLASSES = \
-               ExThread.java \
+               ThreadJob.java \
                Main.java
 
 #
similarity index 74%
rename from TD1/exo2/ExThread.java
rename to TD1/exo2/ThreadJob.java
index 387ea8da3a05f9d8091015960c8edef9b318edcd..dae83baa750588b57e0523d1a0797e56241951e9 100644 (file)
@@ -1,9 +1,8 @@
 import java.util.Random;
 
-public class ExThread implements Runnable {
-    String threadName;
+public class ThreadJob implements Runnable {
 
-    ExThread(String name) {
+    ThreadJob(String name) {
         setName(name);
     }
 
@@ -22,7 +21,7 @@ public class ExThread implements Runnable {
                 // this part is executed when an exception (in this example InterruptedException) occurs
             }
             String threadName = Thread.currentThread().getName();
-            System.out.println(threadName + " has sleept for " + sleep_time + " ms for the " + (j + 1) + " times");
+            System.out.println(threadName + " has slept for " + sleep_time + " ms for the " + (j + 1) + " times");
         }
     }
 }