From a60f224faefee0eac18ce034ee908013f9cbff25 Mon Sep 17 00:00:00 2001 From: "@hexlet/cli" Date: Wed, 21 Feb 2024 13:22:35 +0300 Subject: [PATCH] submit java-advanced-ru/sync-primitives --- .current.json | 2 +- java-advanced-ru/sync-primitives/.gitignore | 8 +-- .../src/main/java/exercise/App.java | 44 ++++++++-------- .../src/main/java/exercise/ListThread.java | 44 ++++++++-------- .../src/main/java/exercise/SafetyList.java | 52 +++++++++---------- 5 files changed, 75 insertions(+), 75 deletions(-) diff --git a/.current.json b/.current.json index 583be33..c0f15d3 100644 --- a/.current.json +++ b/.current.json @@ -1 +1 @@ -{"assignment":"java-advanced-ru/multithreading-java"} +{"assignment":"java-advanced-ru/sync-primitives"} diff --git a/java-advanced-ru/sync-primitives/.gitignore b/java-advanced-ru/sync-primitives/.gitignore index 184bfba..30f448d 100644 --- a/java-advanced-ru/sync-primitives/.gitignore +++ b/java-advanced-ru/sync-primitives/.gitignore @@ -1,4 +1,4 @@ -.gradle/ -build/ -caches/ -.idea/ +.gradle/ +build/ +caches/ +.idea/ diff --git a/java-advanced-ru/sync-primitives/src/main/java/exercise/App.java b/java-advanced-ru/sync-primitives/src/main/java/exercise/App.java index c00b834..1cda66a 100644 --- a/java-advanced-ru/sync-primitives/src/main/java/exercise/App.java +++ b/java-advanced-ru/sync-primitives/src/main/java/exercise/App.java @@ -1,22 +1,22 @@ -package exercise; - -class App { - - public static void main(String[] args) { - // BEGIN - var list = new SafetyList(); - var thread1 = new ListThread(list); - var thread2 = new ListThread(list); - thread1.start(); - thread2.start(); - try { - thread1.join(); - thread2.join(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - System.out.println(list.getSize()); - // END - } -} - +package exercise; + +class App { + + public static void main(String[] args) { + // BEGIN + var list = new SafetyList(); + var thread1 = new ListThread(list); + var thread2 = new ListThread(list); + thread1.start(); + thread2.start(); + try { + thread1.join(); + thread2.join(); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.out.println(list.getSize()); + // END + } +} + diff --git a/java-advanced-ru/sync-primitives/src/main/java/exercise/ListThread.java b/java-advanced-ru/sync-primitives/src/main/java/exercise/ListThread.java index e202a4f..f645410 100644 --- a/java-advanced-ru/sync-primitives/src/main/java/exercise/ListThread.java +++ b/java-advanced-ru/sync-primitives/src/main/java/exercise/ListThread.java @@ -1,22 +1,22 @@ -package exercise; - -// BEGIN -public class ListThread extends Thread { - SafetyList list; - public ListThread(SafetyList list) { - this.list = list; - } - - @Override - public void run() { - for (int i = 0; i < 1000; i++){ - try { - Thread.sleep(1); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - list.add((int) (Math.random() * 1000)); - } - } -} -// END +package exercise; + +// BEGIN +public class ListThread extends Thread { + SafetyList list; + public ListThread(SafetyList list) { + this.list = list; + } + + @Override + public void run() { + for (int i = 0; i < 1000; i++){ + try { + Thread.sleep(1); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + list.add((int) (Math.random() * 1000)); + } + } +} +// END diff --git a/java-advanced-ru/sync-primitives/src/main/java/exercise/SafetyList.java b/java-advanced-ru/sync-primitives/src/main/java/exercise/SafetyList.java index e441e28..79398c9 100644 --- a/java-advanced-ru/sync-primitives/src/main/java/exercise/SafetyList.java +++ b/java-advanced-ru/sync-primitives/src/main/java/exercise/SafetyList.java @@ -1,26 +1,26 @@ -package exercise; - -class SafetyList { - // BEGIN - int[] array; - int size; - - SafetyList() { - array = new int[2100]; - size = 0; - } - - synchronized void add(int number) { - array[size] = number; - size++; - } - - public int get(int index) { - return index > size ? 0 : array[index]; - } - - public int getSize() { - return this.size; - } - // END -} +package exercise; + +class SafetyList { + // BEGIN + int[] array; + int size; + + SafetyList() { + array = new int[2100]; + size = 0; + } + + synchronized void add(int number) { + array[size] = number; + size++; + } + + public int get(int index) { + return index > size ? 0 : array[index]; + } + + public int getSize() { + return this.size; + } + // END +}