读书人

黑马软件工程师-java基础复习-线程-同

发布时间: 2013-07-08 14:13:00 作者: rapoo

黑马程序员--java基础复习--线程--同步与通信
package thread;public class TestThread {private static int count;int line = 5;public static void main(String[] args) {TestThread tt = new TestThread();tt.startThread();tt.startThread();}class CountThread implements Runnable {public void run() {while (count < 25) {//synchronized (TestThread.class) {//if(count < 25){count++;System.out.print(Thread.currentThread().getName() + "--" + count + "\t");line--;if (line == 0) {System.out.println();line = 5;}}//}//}}}public void startThread() {new Thread(new CountThread()).start();}}

package thread;public class TestThread {private static int count;int line = 5;public static void main(String[] args) {TestThread tt = new TestThread();tt.startThread();tt.startThread();}class CountThread implements Runnable {public void run() {while (count < 25) {synchronized (TestThread.class) {if(count < 25){count++;System.out.print(Thread.currentThread().getName() + "--" + count + "\t");line--;if (line == 0) {System.out.println();line = 5;}}}}}}public void startThread() {new Thread(new CountThread()).start();}}


?

当然这是最背的情况,实际情况更复杂,需要用配合代码来说明的。

?

----------------------?ASP.Net+Android+IOS开发、.Net培训、期待与您交流! ----------------------

详细请查看:http://edu.csdn.net

读书人网 >编程

热点推荐