Methods Summary |
---|
public static void | intensiveWork()
//simulate some intensive work
for(int i = WORK; i > 0; i--);
|
public static void | main(java.lang.String[] args)
REPEAT = (args.length > 0) ? Integer.parseInt(args[0]) : 10;
WORK = (args.length > 1) ? Integer.parseInt(args[1]) : 1000000;
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
(new Thread(new ExplicitLocks1())).start();
|
public void | run()
if (startTime == -1)
startTime = System.currentTimeMillis();
for (int i = -REPEAT; i < REPEAT; i++)
{
updateBlueBox(i);
updateRedBox(i);
}
System.out.println("Time taken: " + (System.currentTimeMillis()-startTime));
|
public synchronized void | updateBlueBox(int addition)
blueBoxes += addition;
intensiveWork();
|
public synchronized void | updateRedBox(int addition)
redBoxes += addition;
intensiveWork();
|