Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Thread.sleep() not working

807580Mar 24 2010 — edited Mar 24 2010
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;
	}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 21 2010
Added on Mar 24 2010
5 comments
2,647 views