Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2007, 05:54 AM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
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 ?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-18-2007, 05:59 AM
Senior Member
 
Join Date: Mar 2007
Posts: 136
goldhouse is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-11-2007, 12:39 PM
Member
 
Join Date: Dec 2007
Posts: 3
ingle.anil is on a distinguished road
its call cheep read n write approach.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 04-23-2008, 09:38 PM
danielstoner's Avatar
Senior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 117
danielstoner is on a distinguished road
Read this: Java theory and practice: Managing volatility

and this:
Use synchronized or volatile when accessing shared variables
__________________
Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
volatile variable Java Tip Java Tips 0 12-11-2007 11:26 AM
Keyword : volatile peiceonly Advanced Java 6 08-10-2007 10:26 AM


All times are GMT +3. The time now is 11:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org