javamultithreadingexceptionawtrobotfest

Thread.sleep(time) vs. robot.wait(time)


I'm trying to write some GUI and integration tests using JUnit and FEST. Here is what I have:

@Before
public void setUp(){
    try{
        program.main(args);
        robot.wait(30000);    //gives IllegalMonitorStateException
        Thread.sleep(30000);  //no Exception occurs here
    } catch (Exception e){
        e.printStackTrace();
    }
}

robot and args are already initialized.

Why do I get such an exception when I call wait? Why I don't get the same exception when I call sleep?


Solution

  • You're calling Object.wait() - which is not the same as Thread.sleep(). In particular: