We want to connect the people who have knowledge to the people who need it, to bring together people with different perspectives so they can understand each other better, and to empower everyone to share their knowledge.
import java.util.ArrayList; public class ThreadTest { static int count = 0; public static void main(String[] args) throws InterruptedException { ArrayList<Thread> list = new ArrayList<>(); for (int i = 0; i < 50; i++) { Thread th = new Thread(new Runnable() { @Override public void run() { for (int i = 0; i < 200000; i++) { count++; } } }); th.start(); list.add(th); } for (Thread thread : list) { try { thread.join(); } catch (InterruptedException ex) { } } System.out.println("Count: "+count); } }
public class MultiThreadCountingTest { static AtomicInteger count = new AtomicInteger(); public static void main(String[] args) throws Exception { int threadCount = 50; List list = new ArrayList(); for (int i = 0; i { for (int i1 = 0; i1 < 200000; i1++) { count.incrementAndGet(); } }); th.start(); list.add(th); } for (Thread thread : list) { thread.join(); } System.out.println("Count: "+count); } }
public class MultiThreadCountingTest { static AtomicInteger count = new AtomicInteger(); public static void main(String[] args) throws Exception { int threadCount = 50; CountDownLatch countDownLatch = new CountDownLatch(threadCount); for (int i = 0; i { for (int i1 = 0; i1 < 200000; i1++) { count.incrementAndGet(); } countDownLatch.countDown(); }); th.start(); } countDownLatch.await(); System.out.println("Count: "+count); } }
public class MultiThreadCountingTest { static AtomicInteger count = new AtomicInteger(); public static void main(String[] args) throws Exception { int threadCount = 50; AtomicInteger doneCount = new AtomicInteger(); for (int i = 0; i { for (int i1 = 0; i1 < 200000; i1++) { count.incrementAndGet(); } doneCount.incrementAndGet(); }); th.start(); } while (doneCount.get() != threadCount) { Thread.sleep(1); } System.out.println("Count: "+count); } }
2.2K Point(s)
1.2K Point(s)
313 Point(s)
178 Point(s)
138 Point(s)
Input your email to receive reset password link, or if you remember your password, you can click