Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25
  1. #21
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    i asked "happens-before" question after reading java tutorial only,but i did n't get proper idea on that ,that's why i asked same question here.

  2. #22
    Singing Boyo is offline Senior Member
    Join Date
    Mar 2009
    Posts
    552
    Rep Power
    6

    Default

    hmm... I've never really looked into it. It's something I always recognized, and so I never looked into it deeply. However, it regards the fact that a Thread may access data that is, by the the time the access is complete, incorrect. This is due to fields being edited at the same time by different threads. A happens-before relationship is established when the programmer ensures that a field or method that is accessed by multiple Threads can only be accessed by one at a time. The most common way of doing this is through synchronization.

    Fundamentally, a happens-before relationship means that one Thread will always recognize that another Thread edited the field being accessed, whether that access is achieved directly or through methods.
    If the above doesn't make sense to you, ignore it, but remember it - might be useful!
    And if you just randomly taught yourself to program, well... you're just like me!

  3. #23
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Fundamentally, a happens-before relationship means that one Thread will always recognize that another Thread edited the field being accessed, whether that access is achieved directly or through methods
    Is it means one Thread actions are viewable to other Threads

  4. #24
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    6

    Default

    Think of "happens before" has meaning "will behave as expected if occurs in time before...". In terms of how the Java Virtual Machine is strictly defined to operate, there's a list of certain threading-related actions which are defined to have a "happens before" relationship.

    But it's not necessarily the most practical way of remembering how to program correctly. The golden rule you need to keep in your head is that if data is accessed by more than one thread, you need to do something to make sure that that access is safe. That "something" could be using synchronized, volatile, final, using one of the concurrency utility classes such as ConcurrentHashMap etc etc. I'd recommend learning about these things rather than getting too bogged down in the JVM definition to start with.

    The thing that generally goes wrong in threading/concurrent programming is when people try to be too clever and deliberately flout the basic rules that they know. For example, they invent some clever way to "avoid synchronization". So long as you just follow the rules rather than trying to come up with some clever way to not follow the rules, you'll generally be fine...

  5. #25
    sandeepsai39 is offline Member
    Join Date
    Feb 2009
    Posts
    96
    Rep Power
    0

    Default

    Thanks for all for your valuable sugggestions .I am sure i will come back again with another thrread bcs i have lot of questions in my mind

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Java Threads Interview Question
    By _tony in forum Threads and Synchronization
    Replies: 20
    Last Post: 12-22-2008, 08:31 AM
  2. can you give-me a little hand about java threads?
    By masdrobeda in forum New To Java
    Replies: 3
    Last Post: 11-10-2008, 05:15 PM
  3. How to use Java threads
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:30 PM

Posting Permissions

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