IllegalMonitorStateException...Help!

I am having an Illegal Monitor State Exception error. I have read the java API multiple times and I know why this exception is thrown, I just don't know how to fix it. Can someone please help? I have been working on this for a while and I have tried multiple ways to implement this. I am open to suggestions! The error occurs with the line mainThread.wait();

public class ThreadControl {

private Tier tierPanel;

private Thread mainThread, appThread;

private BallApp _ballApp;

public ThreadControl() {

tierPanel = new Tier(this);

mainThread = new Thread(tierPanel, "Tier");

}

synchronized void resumeTier() {

try{ appThread.wait(); }

catch(InterruptedException e) {}

mainThread.notify();

}

synchronized void startTier() {

mainThread.start();

}

synchronized void startBallApp(int FORstartValue1, int startValue2, int startValue3, int startValue4, int startValue5,

int startValueGC, int startValueIPA, int startValueNumAssim, int startValueNumActors) throws InterruptedException {

_ballApp = new BallApp("ID1_"+FORstartValue1+"finalData.txt", "ID1_"+FORstartValue1+"clusterData.txt", "ID1_"+FORstartValue1+"charData.txt",

FORstartValue1, startValue2, startValue3, startValue4, startValue5, startValueGC, startValueIPA, startValueNumAssim, startValueNumActors, this);

appThread = new Thread(_ballApp, "BallApp");

mainThread.wait();

appThread.start();

}

private static void createAndShowGUI() {

ThreadControl theThreadController = new ThreadControl();

}

public static void main(String[] args) {

javax.swing.SwingUtilities.invokeLater(new Runnable() {

public void run() {

createAndShowGUI();

}

});

}

}

[1818 byte] By [bbass328a] at [2007-11-26 17:43:37]
# 1

You have to synchronize on the object you're waiting on or notifying:

synchronized (object)

{

object.wait();

}

synchronized (object)

{

object.notify();

}

ejpa at 2007-7-9 0:11:48 > top of Java-index,Core,Core APIs...
# 2
Thanks. Wow Why wasnt that clearer on the website?that definitely helped.
bbass328a at 2007-7-9 0:11:48 > top of Java-index,Core,Core APIs...
# 3

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html#notify()

' This method should only be called by a thread that is the owner of this object's monitor. A thread becomes the owner of the object's monitor in one of three ways:

* By executing a synchronized instance method of that object.

* By executing the body of a synchronized statement that synchronizes on the object.

* For objects of type Class, by executing a synchronized static method of that class.'

Seems pretty clear to me.

ejpa at 2007-7-9 0:11:48 > top of Java-index,Core,Core APIs...