Advertisement
jaVer404

level17.lesson04.task02

Sep 24th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. package com.javarush.test.level17.lesson04.task02;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. /* Синхронизированные заметки 2
  7. Класс Note будет использоваться нитями. Поэтому сделай так, чтобы ве методы были синхронизированы
  8. */
  9.  
  10. public class Solution {
  11.     public static class Note {
  12.  
  13.         public final List<String> notes = new ArrayList<String>();
  14.  
  15.         public synchronized void addNote(int index, String note) {
  16.             System.out.println("Сейчас будет добавлена заметка [" + note + "] На позицию " + index);
  17.             notes.add(index, note);
  18.             System.out.println("Уже добавлена заметка [" + note + "]");
  19.         }
  20.  
  21.         public synchronized void removeNote(int index) {
  22.             System.out.println("Сейчас будет удалена заметка с позиции " + index);
  23.             String note = notes.remove(index);
  24.             System.out.println("Уже удалена заметка [" + note + "] с позиции " + index);
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement