removed custom name for threads - using internal name instead
This commit is contained in:
parent
dad420e8d8
commit
108cd3259e
@ -8,8 +8,8 @@ package VL14.Aufgabe01;
|
|||||||
class Aufgabe01 {
|
class Aufgabe01 {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Counter counterUp = new Counter("T1", 1, 100);
|
Counter counterUp = new Counter(1, 100);
|
||||||
Counter counterDown = new Counter("T2", -10);
|
Counter counterDown = new Counter(-10);
|
||||||
Thread threadCounterUp = new Thread(counterUp);
|
Thread threadCounterUp = new Thread(counterUp);
|
||||||
Thread threadCounterDown = new Thread(counterDown);
|
Thread threadCounterDown = new Thread(counterDown);
|
||||||
threadCounterUp.start();
|
threadCounterUp.start();
|
||||||
|
@ -10,29 +10,25 @@ public class Counter implements Runnable {
|
|||||||
|
|
||||||
// some information of the counter.
|
// some information of the counter.
|
||||||
private int number;
|
private int number;
|
||||||
private String name;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new counter with initializing the start value.
|
* Create a new counter with initializing the start value.
|
||||||
*
|
*
|
||||||
* @param name The name of the counter.
|
|
||||||
* @param number The number to increment or decrement the counter.
|
* @param number The number to increment or decrement the counter.
|
||||||
* @param start The start value of the counter.
|
* @param start The start value of the counter.
|
||||||
*/
|
*/
|
||||||
public Counter(String name, int number, int start) {
|
public Counter(int number, int start) {
|
||||||
this(name, number);
|
this(number);
|
||||||
counter = start;
|
counter = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new counter without initializing the start value.
|
* Create a new counter without initializing the start value.
|
||||||
*
|
*
|
||||||
* @param name The name of the counter.
|
|
||||||
* @param number The number to increment or decrement the counter.
|
* @param number The number to increment or decrement the counter.
|
||||||
*/
|
*/
|
||||||
public Counter(String name, int number) {
|
public Counter(int number) {
|
||||||
this.number = number;
|
this.number = number;
|
||||||
this.name = name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,7 +46,7 @@ public class Counter implements Runnable {
|
|||||||
private void count() {
|
private void count() {
|
||||||
synchronized (getClass()) {
|
synchronized (getClass()) {
|
||||||
counter += this.number;
|
counter += this.number;
|
||||||
System.out.printf("%3d [%s: %3d]\n", counter, this.name, this.number);
|
System.out.printf("%3d [%s: %3d]\n", counter, Thread.currentThread().getName(), this.number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user