Difference between static and non static variables in multi threading
807580Apr 23 2010 — edited Apr 23 2010I dont understand the significant difference between using static member variable and non static variable in multi threading.
Are they inter-changable?
Example below..
public class StaticThread {
static int staticCounter=10;
int counter=10;
class Thread1 extends Thread
{
public void run()
{
staticCounter++;
counter++;
System.out.println("staticCounter: "+staticCounter);
System.out.println("counter :"+counter);
}
}
public static void main(String args[]) throws InterruptedException
{
StaticThread c=new StaticThread();
for (int i=0;i<5;i++)
{
Thread worker=c.new Thread1();
worker.start();
Thread.sleep(1000);
}
}
}