I'm not too sure on how to do this.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) { } } }
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




Reply With Quote