multithreading - how do i get a functon to repeat in java -


i making slapjack game deck need give cards slapzone every 5 seconds , flip image 2 seconds before turning picture over. know have use thread, can't figure out how repeat every 5 seconds know repeating part take loop though.

code:

public void run () {     thread thisthread = thread.currentthread();          while (thisthread == mythread)              {         try         {             (int = 0 ; < numcards ; i++)             {                 deck.giveslapzone(slap1);              }              mythread = null;                // kills thread          }         catch (interruptedexception ie)          {             system.out.println(ie.getmessage());             }     } } 

you can use scheduledthreadpoolexecutor if believe may grow past trivial implementation. scheduler thread handle multiple threads , exceptions in smoother manner.

see example in...

timertask vs thread.sleep vs handler postdelayed - accurate call function every n milliseconds?


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -