/
SofiMut
/
concurrentCollection
Обзор
Документация
Войти
/
SofiMut
/
concurrentCollection
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/Main.java
60 строк
2 KB
Sofia Stepanova
first_commit
16 дек 2025, 10:37
16 дек 2025, 10:37
d73dcba
Код
Авторство
О чём код?
import java.util.Random; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; public class Main { public static void main(String[] args) throws InterruptedException { BlockingQueue<String> queue1 = new ArrayBlockingQueue<>(100); BlockingQueue<String> queue2 = new ArrayBlockingQueue<>(100); BlockingQueue<String> queue3 = new ArrayBlockingQueue<>(100); new Thread(() -> { for (int i = 0; i < 10_000; i++) { try { queue1.put(generateText("abc", 100_000)); queue2.put(generateText("abc", 100_000)); queue3.put(generateText("abc", 100_000)); Thread.sleep(100); } catch (InterruptedException e) { return; } } }).start(); new Thread(() -> { }).start(); } public static String generateText(String letters, int length) { Random random = new Random(); StringBuilder text = new StringBuilder(); for (int i = 0; i < length; i++) { text.append(letters.charAt(random.nextInt(letters.length()))); } return text.toString(); } public static MaxTextABC<String, Integer> getMax(BlockingQueue<String> maxABC, char abc) throws InterruptedException { MaxTextABC<String, Integer> maxTextABC = new MaxTextABC<>(); maxTextABC.setCount(0); for (int i = 0; i < 10_000; i++) { int maxInText = 0; String textABC = maxABC.take(); char[] text = textABC.toCharArray(); for (char s : text) { if (s == abc) { maxInText++; } } if (maxInText > maxTextABC.getCount()) { maxTextABC.setCount(maxInText); maxTextABC.setText(textABC); } } return maxTextABC; } }