Click to See Complete Forum and Search --> : Java priority and synchronization
Honey389
July 7th, 2011, 11:56 PM
do i need to use a synchronized keyword in case of thread having different priorities?
if i am having two threads of different priority one with higher and lower and they are sharing the same resource so do i need to synchronize them or not???
D_Drmmr
July 8th, 2011, 05:09 AM
If you want a Java specific answer, you probably shouldn't ask in a C++ forum. ;)
However, your question is actually language independent. The concepts of thread priority and synchronization are orthogonal. Thread priority is about scheduling: which thread is given a time slice when there aren't enough to go around? Synchronization is about preventing race conditions, which can occur irrespective of how you set thread priorities. So yes, you need synchronization if multiple threads access the same resource and at least one of the threads can perform a write operation.
nuzzle
August 13th, 2011, 07:21 PM
if i am having two threads of different priority one with higher and lower and they are sharing the same resource so do i need to synchronize them or not???
In Java you're not synchronizing threads so whatever priority they have doesn't enter the picture,
http://download.oracle.com/javase/tutorial/essential/concurrency/syncmeth.html
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.