рекомендация ментора
Программа вывела в консоль (на экран) слишком много данных.
package com.javarush.task.task17.task1701;
import java.util.ArrayList;
import java.util.List;
/*
Заметки
*/
public class Solution {
public static void main(String[] args) {
new NoteThread ().start ();
new NoteThread ().start ();
}
public static class NoteThread extends Thread {
private int index = 0;
@Override
public void run() {
while (index < 1000) {
try {
System.out.println (getName () + "-Note" + index);
Thread.sleep (1);
Note.removeNote (getName ());
index++;
}catch(InterruptedException e){
}
}
}
}
public static class Note {
public static final List<String> notes = new ArrayList<> ();
public static void addNote(String note) {
notes.add (0, note);
}
public static void removeNote(String threadName) {
String note = notes.remove (0);
if (note == null) {
System.out.println ("Другая нить удалила нашу заметку");
} else if (!note.startsWith (threadName)) {
System.out.println ("Нить [" + threadName + "] удалила чужую заметку [" + note + "]");
} else {
System.out.println ("Нить [" + threadName + "] удалила свою заметку [" + note + "]");
}
}
}
}