package synchronize2;

/**
 * @author Ralf Kunze (rkunze@uos.de), Institut fuer Informatik, Universitaet
 *         Osnabrueck
 * @date 04.05.2007
 */
public class ChangerThread extends Thread {
	Point p;

	public ChangerThread(Point p) {
		this.p = p;
	}

	public void run() {
		int x = (int) (Math.random() * 1000), y = x;

		// Fehlerhafte Synchronisation!!!!
		synchronized (this) {  // es würde auch reichen synchronized { .. zu schreiben

			while (true) {
				p.x = x;
				p.y = y;

				int tx = p.x, ty = p.y;

				if (tx != ty) {
					System.err.printf("OhOh: p.x=%d p.y=%d%n", tx, ty);
				}
			}
		}
	}
}
