import java.awt.Point; import utilities.*; import utilities.beans.*; public class MTProperties extends Thread { protected BrokenProperties myBean; // the target bean to bash.. protected int myID; // each thread carries a bit of ID //------------------------------------------------------------------- // main() entry point //------------------------------------------------------------------- public static void main (String[] args) { BrokenProperties bean; Thread thread; bean = (BrokenProperties) BeansKit.newBean("BrokenProperties"); for (int i=0; i < 20; i++) { // start 10 threads to bash bean thread = new MTProperties(bean, i); // threads get access to bean thread.start(); } } //------------------------------------------------------------------- // MTProperties Constructor //------------------------------------------------------------------- public MTProperties(BrokenProperties bean, int id) { this.myBean = bean; // note the bean to address this.myID = id; // note who we are } //------------------------------------------------------------------- // the thread main loop: // do forever // create new random Point with x == y // tell bean to adopt Point as its new 'spot' property // ask bean what its 'spot' property is now set to // throw a wobbly if spot x does not equal spot y //------------------------------------------------------------------- public void run() { int someInt; Point point = new Point(); while ( true ) { someInt = (int) (Math.random()*100); point.x = someInt; point.y = someInt; myBean.setSpot( point ); point = myBean.getSpot(); if ( point.x != point.y ) { System.out.println("Bean corrupted ! x= " + point.x +", y= " + point.y); System.exit(10); } System.out.print( (char) ('A' + myID) ); System.out.flush(); } } } // End of Class MTProperties