[SOLVED] Thread priority problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 11

[SOLVED] Thread priority problem

Dear fellow programmers Somebody knows why continues giving an arbitraire execution even setting higher priority to one thread respect to another? From PRO exercise found at https://www.sololearn.com/learning/2185/ Initial code: https://code.sololearn.com/cVKM7v9q4FR7/?ref=app My buggy code: https://code.sololearn.com/cOgK28o6QPIH/?ref=app

21st Jan 2021, 11:27 AM
David Ordás
David Ordás - avatar
5 Answers
+ 5
I answered this for Minho 🇰🇷 yesterday. See explanation in this code. https://code.sololearn.com/c9ckWvwXiXcZ/?ref=app
23rd Jan 2021, 1:57 AM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 5
Elizabeth Kelly Minho 🇰🇷 thanks! Its something that I supouse. I know that managing resources are blocking operations and depending on the time taken in resolve them, makes appearing arbitraire results. Let me think if I'm right... Maybe how to solve correctly (producer-consumer pattern) .... - JDK1+ shared mutex object calling method wait() in one thread and notify() in the other. - JDK5+ using concurrent/atomic pkg: Semaphore / Countdown Barrier, AtomicInteger... The extrange thing is that an official SoloLearn practice hints you to resolve it using thread priorities 🤔🤔. So...Might be a buggy exercise 😂😂 ???
25th Jan 2021, 3:59 PM
David Ordás
David Ordás - avatar
+ 4
David Ordás if a producer / consumer solution is required, the recommendation is to use ‘synchronized’ methods for managing access to the shared resource. That is the current standard with JDK11 anyways.
25th Jan 2021, 10:19 PM
Elizabeth Kelly
Elizabeth Kelly - avatar
+ 2
Same problem https://www.sololearn.com/Discuss/2606071/?ref=app Threads depends on OS support and the scheduler in charge to orchetation takes the lastest word independiently of setted priority. Once look at this : https://www.sololearn.com/Discuss/2211828/?ref=app
25th Jan 2021, 4:56 PM
David Ordás
David Ordás - avatar
25th Jan 2021, 7:26 PM
David Ordás
David Ordás - avatar