multithreading - Invoking different methods within one runnable thread in java -
as far understanding far; class implements runnable seems able perform 1 set task within run method. how possible create new thread , run different methods 1 additional thread, without needing create new runnable class every set task.
your runnable class can call logic likes. logic want run must in class, different methods of runnable class or in lots of other classes.
how did plan tell runnable do?
you like:
myrunnable implements runnable { private string m_whattodo; public myrunnable(string whattodo) { m_whattodo = whattodo; } public void runnable run() { if ("x".equals(m_whattodo) { // code x } else if ( "y".equals(m_whattodo) { // code y } else { // error handling } } }
or srikanth says communicate intent other means such thread names.
however don't see overhead in creating runnable class. adding public void run() class surely not big deal?
Comments
Post a Comment