Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.concurrent.*;
- import java.util.concurrent.atomic.*;
- import java.util.concurrent.locks.*;
- class test implements Runnable {
- AtomicLong al = new AtomicLong(0);
- final long n = 40000000l;
- public void run() {
- for(long i=0; i<n; i++)
- al.incrementAndGet();
- }
- public static void main(String [] args) throws Exception {
- test inst = new test();
- inst.run(); // warm-up
- long start = System.nanoTime();
- inst.run();
- inst.run();
- long end1 = System.nanoTime() - start;
- System.out.println("" + end1 / (double)inst.n);
- Thread t1 = new Thread(inst);
- Thread t2 = new Thread(inst);
- start = System.nanoTime();
- t1.start();
- t2.start();
- t1.join();
- t2.join();
- long end2 = System.nanoTime() - start;
- System.out.println("" + end2 / (double)inst.n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment