From 06566a55e1640e3c2c22785dd5ce7d19c947940a Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 6 Mar 2018 18:20:11 +0100 Subject: [PATCH] TD1: Cleanup the exo1 code. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- TD1/exo2/Main.java | 13 ++++++------- TD1/exo2/Makefile | 2 +- TD1/exo2/{ExThread.java => ThreadJob.java} | 7 +++---- 3 files changed, 10 insertions(+), 12 deletions(-) rename TD1/exo2/{ExThread.java => ThreadJob.java} (74%) diff --git a/TD1/exo2/Main.java b/TD1/exo2/Main.java index d28e6b3..9bab323 100644 --- a/TD1/exo2/Main.java +++ b/TD1/exo2/Main.java @@ -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"); diff --git a/TD1/exo2/Makefile b/TD1/exo2/Makefile index e589d5d..648bd38 100644 --- a/TD1/exo2/Makefile +++ b/TD1/exo2/Makefile @@ -46,7 +46,7 @@ JVM = java # NAME = Camilo Juan CLASSES = \ - ExThread.java \ + ThreadJob.java \ Main.java # diff --git a/TD1/exo2/ExThread.java b/TD1/exo2/ThreadJob.java similarity index 74% rename from TD1/exo2/ExThread.java rename to TD1/exo2/ThreadJob.java index 387ea8d..dae83ba 100644 --- a/TD1/exo2/ExThread.java +++ b/TD1/exo2/ThreadJob.java @@ -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"); } } } -- 2.34.1