• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reg : static and volatile  RSS feed

 
chinna talluru
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
static can be used in context where we want to access the content without
creating instance of the class.

e.g : class main method is called without creating instance because main method is static.

volatile variable comes in Thread context.if we specify a variable of type
volatile,then if 10 threads are accessing the some variable, then each thread will get its own local copy.

i think you got it.
ok take care byee
 
Ganesh Kumar
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i got it!! Thanks
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by chinna talluru:
volatile variable comes in Thread context.if we specify a variable of type
volatile,then if 10 threads are accessing the some variable, then each thread will get its own local copy.


Er, isn't that the exact opposite of what "volatile" means?

An ordinary field (not declared "volatile") is allowed to have a separate copy per thread, if the JVM deems that would improve performance. These copies will only be reconciled at synchronisation boundaries.

A "volatile" field always has the same value in all threads.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!