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. good
View Tutorial          By: gummalla subbarao at 2011-03-09 01:24:58

2. HELP ME HOW TO ANALZE THE PROGRAM??????????
View Tutorial          By: MICHELLE FLORES at 2009-01-21 23:24:52

3. Hi I am new to struts framework. Can u tell how to
View Tutorial          By: Nithya at 2012-11-27 14:03:46

4. are you have java code to read sms from gsm modem,
View Tutorial          By: ronized at 2009-01-01 20:36:24

5. Nice example to understand what does the string To
View Tutorial          By: Spha at 2011-07-14 08:00:03

6. hi i am shahid i have made SMS application in j2me
View Tutorial          By: shahid khan at 2012-06-18 13:19:06

7. Hi Jigar,
The above applicatio

View Tutorial          By: Kiran at 2011-12-26 04:00:24

8. i am looking for the samples in java programming u
View Tutorial          By: mary grace leron at 2010-02-18 01:50:50

9. Wow, damn nice. It does everything, and the script
View Tutorial          By: Ethan Windsor at 2012-06-14 13:47:39

10. Brief but Comprehensive. Excellent Effort.
View Tutorial          By: Farooq at 2011-11-16 14:14:52