multithreading - Retrieve list of yielded threads in java -


in java there api helps retrieval of yielded threads, trying prepare sample program learn , see yielding listing yielded threads, couldn't.

1 more doubt have once yielded thread run again or runs point stopped. per observations starts same stacktrace run not called on , on again. correct ?

yielding makes thread state runnable can differentiated other threads in runnable state.

or other program states yielded threads. putting sample working on too..

public class threadyielddemo implements runnable {      thread t;      threadyielddemo(string str) throws interruptedexception {          t = new thread(this, str);         system.out.println(" state = "+t.getstate()+" "+str);         t.start();         system.out.println(" state-1 = "+t.getstate()+" "+str);     }      public void run() {         system.out.println("entry = "+thread.currentthread().getname()+"  state = "+thread.currentthread().getstate());         random random = new random();         int next = random.nextint(10);         if(next%2==0)         {             system.out.println(thread.currentthread().getname());             system.out.println("in: "+thread.currentthread().getstate());          }         else         {             system.out.println(thread.currentthread().getname()+" yielded...");             thread.yield();             try {                 thread.sleep(3000);             } catch (interruptedexception e) {                 // todo auto-generated catch block                 e.printstacktrace();             }              system.out.println("yield = "+thread.currentthread().getstate());         }        }      public static void main(string[] args) throws interruptedexception {         new threadyielddemo("thread 1");         new threadyielddemo("thread 2");         new threadyielddemo("thread 3");         new threadyielddemo("thread 4");         new threadyielddemo("thread 5");     } }  

you can't in code.

but can use jstack or profiler may show more details. still think won't show if thread yielded...


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -