import java.util.Random;

public class LockContention {
    static Random randomGen = new Random();
    static int NTHREAD = 100;

    static public void main(String args[]) {
        Runnable task = () -> {
            for (int i = 0; i < 10000000; i++)
                randomGen.nextInt(1000);
        };

        Thread threads[] = new Thread[NTHREAD];
        for (int i = 0; i < NTHREAD; i++) {
            threads[i] = new Thread(task);
            threads[i].start();
        }
        try {
            for (Thread t : threads)
                t.join();
        } catch (InterruptedException e) {
            System.err.println("Interrupted: " + e);
        }
    }
}

@@ -122,18 +122,85 @@
 HREAD = 
-10
+7;%0D%0A    static Object lock = new Object();%0D%0A    static int counter = 
 0;%0D%0A%0D%0A  
@@ -314,18 +314,16 @@
 %3C 100000
-00
 ; i++)%0D%0A
@@ -342,32 +342,301 @@
     
-randomGen.nextInt(1000);
+synchronized (lock) %7B%0D%0A                    try %7B%0D%0A                        Thread.sleep(50);%0D%0A                    %7D catch (InterruptedException e) %7B%0D%0A                        System.err.println(%22Interrupted sleep: %22 + e);%0D%0A                    %7D%0D%0A                    counter++;%0D%0A                %7D
 %0D%0A  
@@ -945,32 +945,32 @@
 Exception e) %7B%0D%0A
-
             Syst
@@ -996,16 +996,21 @@
 errupted
+ join
 : %22 + e)

Use sleep rather than Random