曦~妍  

2016年6月4日

摘要: 1 package xiancheng; 2 import java.util.*; 3 public class Test1 extends Thread { 4 /*随便选择两个城市作为预选旅游目标。实现两个独立的线程分别显示10次城市名,每次显示后休眠一段随机时间(1000ms以内), 5 * 哪个先显示完毕,就决定去哪个城市。分别用Runnable接口... 阅读全文
posted @ 2016-06-04 09:57 曦~妍 阅读(301) 评论(0) 推荐(0)
 
摘要: 1 package xiancheng; 2 3 4 import java.util.Random; 5 6 public class Test2 implements Runnable { 7 8 @Override 9 public void run() { 10 11 city(); 12 13 ... 阅读全文
posted @ 2016-06-04 09:56 曦~妍 阅读(163) 评论(0) 推荐(0)
 
摘要: 1 package xiancheng; 2 3 public class Test5 implements Runnable{ 4 5 static int piaos=10; 6 public void run() 7 { 8 //卖票 9 while(true) 10 { 11... 阅读全文
posted @ 2016-06-04 09:52 曦~妍 阅读(164) 评论(0) 推荐(0)
 
摘要: 1 package xiancheng; 2 3 public class Test4 extends Thread{ 4 static int piaos=10; 5 public void run() 6 { 7 //卖票 8 // while(true) 9 // { 10 // try { 阅读全文
posted @ 2016-06-04 09:51 曦~妍 阅读(147) 评论(0) 推荐(0)
 
摘要: synchronized在多线程中的使用 synchronized在多线程中的使用 synchronized在多线程中的使用 先看一个例子: //模仿火车售票系统,假设有4个售票点同时售票,我们可以把四个售票点定义为四个独立线程 class Test{ public static void main 阅读全文
posted @ 2016-06-04 09:40 曦~妍 阅读(148) 评论(0) 推荐(0)