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. hi ... i want to receive SMS on the com port ... b
View Tutorial          By: Ahsan at 2010-02-16 19:49:26

2. Please help me send sms. I did everything , But no
View Tutorial          By: Prabhash V S at 2009-06-03 06:40:55

3. Thank you for such a article. It is extreamly nice
View Tutorial          By: Ravi at 2011-08-23 10:04:14

4. Nicely explained concept. Thankx.
View Tutorial          By: Raghvendra at 2013-01-17 07:48:18

5. useful for me
View Tutorial          By: ganga at 2010-10-06 00:51:51

6. hi ..........
the code is worked for me....

View Tutorial          By: pradeep at 2012-01-25 06:30:14

7. HI all,

I am not able to call SMSC

View Tutorial          By: chinnadurai at 2009-08-26 23:58:54

8. why do't you create ActionErrors object like this<
View Tutorial          By: veera reddy at 2011-07-15 12:14:57

9. This website is great for the students who want to
View Tutorial          By: Parth Patalia at 2009-11-19 21:09:24

10. i am try this codeing in vb . i am using nokia n73
View Tutorial          By: kanyaraj at 2010-02-09 19:10:10