java - How is minimum priority thread getting executed before maximum priority thread? -



java - How is minimum priority thread getting executed before maximum priority thread? -

while executing code, notice thread minimum priority getting executed before thread maximum priority. can help me understand what's going on here?

class test implements runnable { public void run() { for(int i=0; i<5; i++) system.out.println(thread.currentthread().getname()); } } class testmain { public static void main(string[] args) { test test = new test(); thread t1 = new thread(test); thread t2 = new thread(test); t1.setpriority(thread.max_priority); t1.setname("max priority thread"); t2.setpriority(thread.min_priority); t2.setname("min priority thread"); t1.start(); t2.start(); } }

sometimes, i'm getting output

min priority thread min priority thread min priority thread min priority thread max priority thread max priority thread max priority thread max priority thread max priority thread min priority thread

and

max priority thread max priority thread max priority thread max priority thread max priority thread min priority thread min priority thread min priority thread min priority thread min priority thread

logically, thread maximum priority should start first. not happening. if unavoidable, how create sure thread maximum priority start first?

priorities suggestion scheduler. way guarantee 1 particular thread executes before appropriate concurrency mechanism such countdownlatch.

java multithreading

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -