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,
Please give the better example of resou

View Tutorial          By: Keerthi at 2012-01-11 11:28:24

2. hi.I am new in j2me and really want to learn more
View Tutorial          By: snehal at 2011-12-01 11:46:22

3. i need a J2me PIM for accessing phone contact... <
View Tutorial          By: shafique at 2011-06-28 04:11:55

4. Hi i changed some codes in that and i gave interne
View Tutorial          By: Göktuğ ÖZEL at 2013-03-13 22:44:55

5. I'd like to Thanks first bcoz your program is real
View Tutorial          By: Pawan at 2012-04-24 19:46:00

6. Can anybody help me to send the code for email sen
View Tutorial          By: satendra at 2010-03-23 02:46:18

7. All in all is not a comment.bt a question How 2 us
View Tutorial          By: Tkalani at 2009-06-03 02:16:14

8. Hello Everyone
I used this program but i'm

View Tutorial          By: Yougeshwar Khatri at 2011-09-16 08:50:47

9. javax.comm.NoSuchPortException
at javax.co

View Tutorial          By: Prakash at 2008-04-14 06:22:38

10. Thank you lot [email protected]
This example help me.

View Tutorial          By: Tushar at 2012-02-12 02:48:10