总是出现 无法从静态上下文中引用非静态 变量 this,实在不知问题在哪了!
public class ThreadTT {
/**
* Method main
*
*
* @param args
*
*/
static String str="";
public static void main(String[] args) {
// TODO: Add your code here
new Thread(new Say()).start();
int i=0;
while(true)
{
synchronized(str)
{
if(i==5000)
return;
System.out.println("ni hao.");
i++;
}
}
}
class Say implements Runnable
{
public void run()
{
int i=0;
while(true)
{
synchronized(str)
{
if(i==5000)
return;
System.out.println("hello world.");
i++;
}
}
}
}
}
求哪为大哥指点迷津!