FileDocCategorySizeDatePackage
ExplicitLocks1.javaAPI DocExample1523Thu Feb 24 22:14:46 GMT 2000tuning.threads

ExplicitLocks1

public class ExplicitLocks1 extends Object implements Runnable

Fields Summary
static int
REPEAT
static int
WORK
private static long
startTime
static int
blueBoxes
static int
redBoxes
Constructors Summary
Methods Summary
public static voidintensiveWork()

    //simulate some intensive work
    for(int i = WORK; i > 0; i--);
  
public static voidmain(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 voidrun()

    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 voidupdateBlueBox(int addition)

    blueBoxes += addition;
    intensiveWork();
  
public synchronized voidupdateRedBox(int addition)

    redBoxes += addition;
    intensiveWork();