Methods Summary |
---|
static synchronized void | addSuccess()
successCount++;
|
public static void | main(java.lang.String[] args)
MultithreadTestCase testCase = new MultithreadTestCase("MultithreadTestCase");
testCase.testMultithreading();
|
private java.lang.String | printAddress(samples.addr.Address ad)
String out;
if (ad == null)
out = "\t[ADDRESS NOT FOUND!]";
else
out ="\t" + ad.getStreetNum () + " " + ad.getStreetName () + "\n\t" + ad.getCity () + ", " + ad.getState () + " " + ad.getZip () + "\n\t" + printPhone (ad.getPhoneNumber ());
return out;
|
private java.lang.String | printPhone(samples.addr.Phone ph)
String out;
if (ph == null)
out = "[PHONE NUMBER NOT FOUND!]";
else
out ="Phone: (" + ph.getAreaCode () + ") " + ph.getExchange () + "-" + ph.getNumber ();
return out;
|
private synchronized void | setError(junit.framework.AssertionFailedError error)
if (this.error == null) {
this.error = error;
}
|
public void | testMultithreading()
try {
binding = new AddressBookServiceLocator().getAddressBook();
}
catch (ServiceException jre) {
throw new AssertionFailedError("ServiceException caught: " + jre);
}
assertTrue("binding is null", binding != null);
((AddressBookSOAPBindingStub) binding).setMaintainSession(true);
int NUM_THREADS = 50;
Thread[] threads = new Thread[NUM_THREADS];
for (int i = 0; i < NUM_THREADS; ++i) {
threads[i] = new Thread(new Run());
threads[i].start();
}
for (int i = 0; i < NUM_THREADS; ++i) {
try {
threads[i].join();
}
catch (InterruptedException ie) {
}
}
System.out.println("Had " + successCount +
" successes (of a possible " +
(NUM_THREADS * 4) + ")");
if (error != null) {
throw error;
}
|