Results 1 to 4 of 4
  1. #1
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default volatile and synchornized

    volatile make sure the the class variable is latest. synchorized make sure only one thread access it . Cant we replace the volatile with the synchornized ?

  2. #2
    goldhouse is offline Senior Member
    Join Date
    Mar 2007
    Posts
    134
    Rep Power
    0

    Default

    Yes , I got a reason for making the two as different .
    Look we have scenario like this say we have two threads

    First thread need to set the variable for the next thread
    Second thread comes & checks the variable & finds it's not set , it return without doing it's task

    Only volatile can solve this problem

    So the conclusion is volatile is not a replacement for synchronization and vice versa

  3. #3
    ingle.anil is offline Member
    Join Date
    Dec 2007
    Posts
    3
    Rep Power
    0

    Default

    its call cheep read n write approach.

  4. #4
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

Similar Threads

  1. Keyword : volatile
    By peiceonly in forum Advanced Java
    Replies: 13
    Last Post: 11-17-2010, 12:47 PM
  2. volatile variable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 10:26 AM

Posting Permissions

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