Why use volatile variables in java ?

Alok mishra

Alok mishra

@alok-mishra-E4tgN8 Oct 26, 2024
Can anyone make me clear about use of volatile keyword in java ? I would appreciate if one can give related examples ?
Thanks in advance

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Anoop Kumar

    Anoop Kumar

    @anoop-kumar-GDGRCn Sep 12, 2013

    never used volatile variables in real project.
    you can see some stackoverflow discussion, they have some practical examples

    #-Link-Snipped-#

    This discussion is very clear why volatile

    #-Link-Snipped-#
  • Dhaval Pujara

    Dhaval Pujara

    @dhaval-pujara-LGoZAW Sep 15, 2013

    volatile modifier tells the JVM that a threbad accessing a the variable must always reconcile its own private coppy of the variable with master copy in memory ......ALL IN ONE THAT STOP ACCESSING MULTIPLE THREAD TO INSTANCE VARIABLE VOLATILE IS USED ultimatly its only applied to instance variable not local variable