Comment on Tutorial - Transient vs Volatile modifiers in Java By Reema sen



Comment Added by : JavaBoy

Comment Added at : 2011-09-24 05:41:19

Comment on Tutorial : Transient vs Volatile modifiers in Java By Reema sen
Hi there, I fixed the above (non-working) example:

package com.src.volatileExample;

public class MultiThreadingExample implements Runnable {

private volatile int testValue;

public void run()
{
for(int i=0; i<3; i++)
{
try
{
System.out.println(Thread.currentThread().getName()+": "+i);

if(Thread.currentThread().getName().equalsIgnoreCase("T1"))
{
testValue=10;
}
if(Thread.currentThread().getName().equalsIgnoreCase("T2"))
{
System.out.println("Test value: "+testValue);
}

Thread.sleep(1000);
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
}

}

public class VolatileExmaple {

/**
* @param args
*/
public static void main(String[] args) {

MultiThreadingExample volatileExample = new MultiThreadingExample();

Thread t1 = new Thread(volatileExample,"T1");
Thread t2 = new Thread(volatileExample,"T2");

t1.start();
t2.start();

}
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. I wanna to name ,subject and marks of every subjec
View Tutorial          By: raveesh yadav at 2012-10-13 19:56:47

2. Very nice demo. thanks! :)
View Tutorial          By: Nikhil Gala at 2012-01-13 10:03:57

3. I need
text,number,text,number,text,num

View Tutorial          By: kabil dev at 2015-05-29 13:10:40

4. better if it is explained with output of the progr
View Tutorial          By: dinesh at 2013-05-05 13:57:21

5. hello, this code was compiled correctly, bt it wil
View Tutorial          By: anand vijay singh at 2014-05-03 12:47:24

6. I have altered the code as described (xml addition
View Tutorial          By: Spijker at 2015-10-14 12:27:47

7. Thanks a LOT !!
I was confused with this !

View Tutorial          By: rishabhsethi at 2012-10-31 15:07:07

8. Plz can someone help me, I copied the code above a
View Tutorial          By: Dse90 at 2010-02-10 04:28:34

9. sr. habla espanol necesito su ayuda... alguno tien
View Tutorial          By: ROGER HERNANDEZ at 2011-09-13 15:20:01

10. Thanks a lot.. it made my concepts of memmove,mems
View Tutorial          By: Rimmi Jain at 2009-07-23 06:42:01