Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package experiments;
- import java.util.Random;
- public class Main {
- public static void main(String[] args) throws Exception {
- Counter counter = new CounterImpl();
- int numberOfThread = 1_000;
- Thread[] threads = new Thread[numberOfThread];
- class CounterRunner implements Runnable {
- @Override
- public void run() {
- counter.count();
- }//end run
- }// end local class
- for (int i = 0; i < threads.length; i++) {
- threads[i] = new Thread(new CounterRunner());
- threads[i].start();
- }//end for
- // Wait for all sub-threads finish their task
- for (Thread thread : threads) {
- thread.join();
- }//end for
- System.out.println("Count: " +counter.getCounter());
- }//end main
- }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement