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



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. helpfull !!!!
View Tutorial          By: Anonymous at 2009-05-12 03:48:15

2. Nice Example .........than Q!!!
View Tutorial          By: Sreekar at 2011-06-29 15:31:50

3. good example..easy to understand
View Tutorial          By: aleena at 2010-07-24 21:56:01

4. Thanks lot.Its working good...... thanks lot lot..
View Tutorial          By: Mohanraj at 2011-12-07 05:23:26

5. it's very easy simple progremme in java
View Tutorial          By: sambasiva rao at 2010-09-24 23:53:00

6. tnx man that was short and well explained...
View Tutorial          By: jsf noob at 2012-02-02 13:24:12

7. It is simple and clear.. Thnx.
View Tutorial          By: kiru at 2010-04-06 01:48:04

8. Sir , I am doing B.Tech . I want to know more abou
View Tutorial          By: amita saini at 2011-08-05 13:07:35

9. Following line
if (strcmp(dp->

View Tutorial          By: Sebastiaan Jaarsma at 2012-12-24 19:28:43

10. Excellent explanation. How can I take input from t
View Tutorial          By: Joe at 2013-03-31 11:02:28