import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.concurrent.ArrayBlockingQueue;import java.util.concurrent.BlockingQueue;import java.util.concurrent.CountDownLatch;import java.util.concurrent.atomic.AtomicInteger;public class Main22 { private static AtomicInteger count = new AtomicInteger(0); private static final int THREAD_COUNT = 3; public static void main(String[] args) throws IOException, InterruptedException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = null; // Scanner scan = new Scanner(System.in); BlockingQueue<String> bq = new ArrayBlockingQueue<>(200009); while ((line = br.readLine()) != null) { if ("".equals(line)) break; bq.put(line); } bq.add("__QUIT__"); bq.add("__QUIT__"); bq.add("__QUIT__"); CountDownLatch cdl = new CountDownLatch(THREAD_COUNT); Runnable task = new Runnable() { public void run() { while (true) { try { String str = bq.take(); if("__QUIT__".equals(str)){ cdl.countDown(); break; } if (str.contains("u51")) { count.incrementAndGet(); } } catch (InterruptedException e) { throw new RuntimeException(e); } } } }; Thread[] threads = new Thread[THREAD_COUNT]; for (int i = 0; i < THREAD_COUNT; i++) { threads[i] = new Thread(task); threads[i].start(); } cdl.await(); System.out.println(count.get()); }}