Note: this bug is being reopened to enable an escalation - a new
test case should be submitted that reflects the real problem.
Name: rlT66838 Date: 07/22/99
We tried the following example on a Multi-Processor PC with
Windows NT Server 4.0 SP4 (400MHz). Running the example on both CPU's produces a runtime of 2900ms. Setting the cpu affinity in
the WindowsNT taskmanager to one CPU speeds up the example to
150ms!!!
This behavior is terrible because our large server program slows
down by factor 3 on a dual cpu machine but we need a speeup!
Please try the example!
--- Counter.java
import java.util.*;
public class Counter
{
private int counter = 0;
public Counter()
{
}
public synchronized void setCounter(int newCounter)
{
counter = newCounter;
}
public synchronized int getCounter()
{
return counter;
}
public synchronized void doIncrease()
{
counter++;
}
public synchronized void doDecrease()
{
counter--;
}
}
--- CounterThread.java
import java.io.*;
public class CounterThread extends Thread
{
private String threadname = null;
private Counter counter = null;
public CounterThread(Counter counter, String threadname)
{
this.threadname = threadname;
this.counter = counter;
System.err.println("Thread "+threadname+" created");
}
public void run ()
{
System.err.println("Thread "+threadname+" started");
for (int i=0; i<10000; i++)
{
counter.doIncrease();
counter.doDecrease();
}
}
}
--- MultiCPUCounter.java
/*
* This is the main test class.
*/
import java.util.*;
public class MultiCPUCounter
{
private static int THREADCOUNT = 10;
// main routine
public static void main(String[] args)
{
/*
small delay to allow to set the process affinity in the
WindowsNT taskmanager
*/
System.err.println("Waiting some seconds");
for (int i=0; i<10; i++)
{
try{Thread.currentThread().sleep(1000);}catch(InterruptedException e){}
System.err.print(".");
}
System.err.println("starting!");
// init our thread array
CounterThread threadarray[] = new CounterThread[THREADCOUNT];
// init the shared object
Counter counter = new Counter();
// generate threads
for (int i=0; i<THREADCOUNT; i++)
{
threadarray[i] = new CounterThread(counter, String.valueOf(i));
}
long start = System.currentTimeMillis();
// start all threads
for (int i=0; i<THREADCOUNT; i++)
{
CounterThread thread = threadarray[i];
thread.start();
}
// wait till the threads have finished
for (int i=0; i<THREADCOUNT; i++)
{
try
{
CounterThread thread = threadarray[i];
thread.join();
}
catch(InterruptedException e)
{
}
}
// print measurement
long end = System.currentTimeMillis();
System.out.print("Running time:");
System.out.println(end-start);
}
}
java -version
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, nojit)
java -fullversion
java full version "JDK-1.2.2-W"
(Review ID: 88235)
======================================================================
test case should be submitted that reflects the real problem.
Name: rlT66838 Date: 07/22/99
We tried the following example on a Multi-Processor PC with
Windows NT Server 4.0 SP4 (400MHz). Running the example on both CPU's produces a runtime of 2900ms. Setting the cpu affinity in
the WindowsNT taskmanager to one CPU speeds up the example to
150ms!!!
This behavior is terrible because our large server program slows
down by factor 3 on a dual cpu machine but we need a speeup!
Please try the example!
--- Counter.java
import java.util.*;
public class Counter
{
private int counter = 0;
public Counter()
{
}
public synchronized void setCounter(int newCounter)
{
counter = newCounter;
}
public synchronized int getCounter()
{
return counter;
}
public synchronized void doIncrease()
{
counter++;
}
public synchronized void doDecrease()
{
counter--;
}
}
--- CounterThread.java
import java.io.*;
public class CounterThread extends Thread
{
private String threadname = null;
private Counter counter = null;
public CounterThread(Counter counter, String threadname)
{
this.threadname = threadname;
this.counter = counter;
System.err.println("Thread "+threadname+" created");
}
public void run ()
{
System.err.println("Thread "+threadname+" started");
for (int i=0; i<10000; i++)
{
counter.doIncrease();
counter.doDecrease();
}
}
}
--- MultiCPUCounter.java
/*
* This is the main test class.
*/
import java.util.*;
public class MultiCPUCounter
{
private static int THREADCOUNT = 10;
// main routine
public static void main(String[] args)
{
/*
small delay to allow to set the process affinity in the
WindowsNT taskmanager
*/
System.err.println("Waiting some seconds");
for (int i=0; i<10; i++)
{
try{Thread.currentThread().sleep(1000);}catch(InterruptedException e){}
System.err.print(".");
}
System.err.println("starting!");
// init our thread array
CounterThread threadarray[] = new CounterThread[THREADCOUNT];
// init the shared object
Counter counter = new Counter();
// generate threads
for (int i=0; i<THREADCOUNT; i++)
{
threadarray[i] = new CounterThread(counter, String.valueOf(i));
}
long start = System.currentTimeMillis();
// start all threads
for (int i=0; i<THREADCOUNT; i++)
{
CounterThread thread = threadarray[i];
thread.start();
}
// wait till the threads have finished
for (int i=0; i<THREADCOUNT; i++)
{
try
{
CounterThread thread = threadarray[i];
thread.join();
}
catch(InterruptedException e)
{
}
}
// print measurement
long end = System.currentTimeMillis();
System.out.print("Running time:");
System.out.println(end-start);
}
}
java -version
java version "1.2.2"
Classic VM (build JDK-1.2.2-W, native threads, nojit)
java -fullversion
java full version "JDK-1.2.2-W"
(Review ID: 88235)
======================================================================