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 ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).start();
(new Thread(new ExplicitLocks2())).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 static void | updateBlueBox(int addition)
synchronized (BLUE_LOCK) {
blueBoxes += addition;
}
intensiveWork();
|
public static void | updateRedBox(int addition)
synchronized (RED_LOCK) {
redBoxes += addition;
}
intensiveWork();
|