Hi guys I'm having an issue with Thread.sleep() not sleeping. I've searched the forums but haven't really found what I need.
Here is how my code works: first I have a class (running as a Thread) that calls this runLearner() method. That method then calls another method - getNextState() which is where I need to sleep. But it doesn't do it! Any help would be appreciated.
public void run() {
System.out.println("*** ERSAgent Thread started ("+this.name+")... ***");
try {
while(agentRunning && !Thread.interrupted()) {
// run the learning loop
rl.runLearner();
}
} catch (Exception e) {
System.out.println(e.toString() +"\n");+
+ e.printStackTrace();+
+ }+
+ System.out.println("** *ERSAgent Thread ended ("+this.name+"). ***");
rl.getPolicy().setInitValues(rl.getEnvironment().getInitValues());
}
public void runLearner() { ...
newstate = environment.getNextState( action );
...
public int[] getNextState( int action ) {
// send action via OSC
actionMsg = new OSCMessage(this.name, new Object[]{new Integer(action)});
ERS.osc.sendOSC(actionMsg);
System.out.println("Action taken/sent, getting next state...");
try {
Thread.sleep(delay);
} catch(InterruptedException e) {
System.out.println("getNextState() interrupted" +"\n"+ e);
e.printStackTrace();
}
// new state and reward
int[] newState = getState();
System.out.println("Got state, determining reward...");
waitingReward = calcReward();
return newState;
}