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. hi
very tnx for your code

View Tutorial          By: Moji at 2012-08-19 16:06:53

2. i want to knew about byte datatype. why did not by
View Tutorial          By: pankaj kr tiwari at 2011-12-02 04:37:43

3. really superb in simple english with examples. Exp
View Tutorial          By: hariharan at 2009-01-14 22:22:32

4. its useful code.
but i want to write in a f

View Tutorial          By: SARWAR at 2011-08-02 06:26:37

5. CTRL+C then CTRL+V :P
Complete Reference ;)

View Tutorial          By: Rahul A at 2012-03-21 14:12:56

6. I dont want my client using my application to do a
View Tutorial          By: zaffa at 2011-07-27 06:52:09

7. how to import myownclass into another class same p
View Tutorial          By: rana at 2013-04-19 17:32:08

8. really good
View Tutorial          By: ammu at 2009-11-04 05:07:14

9. Thanks

I was really helpful.

View Tutorial          By: saroj khatiwoda at 2015-06-02 12:17:51

10. To determine current location in a file:
{<

View Tutorial          By: Terry at 2009-09-27 13:15:56