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++;
}
}
}
}
}
求哪为大哥指点迷津!
/**
* 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++;
}
}
}
}
}
求哪为大哥指点迷津!
解决方案 »
- 如何throw Exception ?
- synchronized(Thread.currentThread())和synchronized(this)的区别?
- java程序编译??
- 谁有(java 2入门到精通)的电子书啊!
- 几个小问题请教
- 问一下java连接数据库的问题
- 刚学者问一初学问题...public static void main (String args[ ] )
- jcreator想打点能提示出方法名和属性的那个功能怎么没有
- 将数据库某一个表的几行复制到另一个表,应该用怎样的sql语句(java jdbc)(急)
- java编译器
- JAVA操作EXCEL2003怎么操作?
- core java 2 中是不是出错了?
××××××××××××
×× 第一种 ×××
××××××××××××
定义clas Say 为static,使Say 完全独立出来
比如
static class Say implements Runnable ....××××××××××××
×× 第二种 ×××
××××××××××××
在main 中,用ThreadTT 这个类的实体创建Say实体
比如
public static void main(String[] args) {
....
ThreadTT t = new ThreadTT();
new Thread(t.new Say()).start();
....
}
注意这里 t.new 说明ThreadTT 和 Say有包含关系,所以需要一个ThreadTT实体