CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2011
    Posts
    1

    Question Java priority and synchronization

    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???

  2. #2
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Java priority and synchronization

    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.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: Java priority and synchronization

    Quote Originally Posted by Honey389 View Post
    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/tu.../syncmeth.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured