首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

黑马软件工程师-java基础复习-线程-同步与通信

2013-07-08 
黑马程序员--java基础复习--线程--同步与通信package threadpublic class TestThread {private static in

黑马程序员--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

热点排行