Results 1 to 6 of 6

Thread: ComputerJy, need your expert help on threads please

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    ComputerJy, need your expert help on threads please

    Code:
    public class Test {
        public static void main(String[] args) {
    	GamePlayer game = new GamePlayer();
    	
    	System.out.println(game.doSomeMove());
        }
    }
    
    class GamePlayer {
        int doSomeMove() {
    	// Cause some timeout on purpose.. 7 seconds!
    	Long stoptime = 7000L; 
    	
    	try {
    	    Thread.sleep(stoptime);
    	} catch (InterruptedException e) {
    	    e.printStackTrace();
    	}
    
    	return 5;
        }
    }
    
    class ThreadTesting implements Runnable {
        public void start() {
        }
        
        public void stop() {
        }
        
        public void run() {
    	try {
    	}
    	
    	catch (Exception e) {
    	}
        }
    }
    I'm not too sure on how to do this.

    as you see i deliberately make the doSomeMove() return the int after 7 seconds. i want to somehow run the doSomeMove() method in a thread and check it for timeout issues. If the method takes more than 5 seconds to respond, i want to stop the thread and print "player move took too long to repsond" otherwise i return the move (the int) as normal. can anyone help me with this
    Last edited by Pouncer; Jul 18th, 2008 at 05:47 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width