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. it is very useful to others............,thanx
View Tutorial          By: jey at 2012-01-06 08:53:22

2. sir needed help i am compiler dev c++ which shown
View Tutorial          By: shahab at 2010-05-05 13:17:53

3. i m new in java plz send some programs on packages
View Tutorial          By: zainul hasan mirza at 2009-08-31 02:28:32

4. Hi DILIP !
Can you plz help me I have an ex

View Tutorial          By: Bull at 2012-01-25 16:16:36

5. thanks .
it helps easy to connect..

View Tutorial          By: bastin at 2011-12-09 19:49:34

6. hi
thanks for your code i wanted to know w

View Tutorial          By: anshul at 2009-10-28 15:10:10

7. thank's for the info.. i've learned a lot.. now, i
View Tutorial          By: farah talabo at 2012-01-08 23:55:14

8. good
View Tutorial          By: saravanan at 2007-03-02 23:16:00

9. Puedes enviarme ese codigo, ando embolatado
View Tutorial          By: Wilson at 2011-10-26 22:45:38

10. very good
View Tutorial          By: Deepika at 2012-03-26 07:00:29