/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author martijn
*/
public class Counter
{
public int i;
public static void main(String[] args)
{
sephyDemoNotWorking();
try {
Thread.sleep(2000);
} catch (Exception e) {
}
;
sephyDemoWorking();
}
private static void sephyDemoNotWorking()
{
final Counter c = new Counter();
c.i = 1;
do {
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
try {
Thread.sleep(100); // Thread.sleep which simulates the tv.post
} catch (Exception e) {
}
System.out.println(c.i);
}
});
t.start();
c.i++;
try {
Thread.sleep(10);
} catch (Exception e) {
}
} while (c.i < 16);
}
private static void sephyDemoWorking()
{
int i = 1;
do {
final int localCopy = i;
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
try {
Thread.sleep(100); // Thread.sleep which simulates the tv.post
} catch (Exception e) {
}
System.out.println(localCopy);
}
});
t.start();
i++;
try {
Thread.sleep(10);
} catch (Exception e) {
}
} while (i < 16);
}
}