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 like the example and it helped me understand the
View Tutorial          By: Danny at 2009-10-23 02:09:06

2. YA IT'S VERY USEFUL
View Tutorial          By: JOTHIBASU at 2010-12-20 05:29:38

3. HI your explanation is absolutely correct but I am
View Tutorial          By: Anil R. Chinchawade at 2010-07-28 02:02:01

4. Thanks Steven, That is an exhaustive list of diffe
View Tutorial          By: Robert at 2008-12-08 22:17:47

5. good example need some more explanation on notify
View Tutorial          By: prashant at 2009-09-08 19:29:54

6. i want to open pdf file from sd card and i dont wa
View Tutorial          By: Karan Mavadhiya at 2013-01-30 12:02:30

7. hi i m deepika mittal . i m working on the same pr
View Tutorial          By: deepika Mittal at 2009-05-30 06:55:22

8. what are the required equipments to run j2me
View Tutorial          By: messi at 2012-11-13 13:15:18

9. When i run the program,Iam getting this

View Tutorial          By: anitha at 2008-12-17 21:37:36

10. its working... thanks.. thank you very much...!!!!
View Tutorial          By: Viswanathan at 2008-08-18 06:54:09