- package duoxiancheng;
- class person implements Runnable{
-
- int person = 1000;
- Object obj =new Object();
- public void run(){
- while(true){
-
- synchronized (obj) {
- if (person > 0) {
- System.out.println("杀手"+Thread.currentThread().getName() + " 正在杀 "
- +"第" +person--+"个人");
- }
- else{
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("杀人完毕!!!!!!!!!!");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("天亮了!!!!!请睁眼!!!!!!");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("警察请指认");
- try {
- Thread.sleep(5100);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("死了"+"1000"+"人"+"我也没办法");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- System.out.println("我还是先回睡觉去!!!!~~~~~~");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- System.out.println("拜拜");
- System.exit(person);
- }
- }
-
-
- }
-
- }
- }
- public class KillPersonGame {
-
- public static void main(String[] args) {
- System.out.println("天黑了,请闭眼,杀手请杀人");
- try {
- Thread.sleep(5000);
- } catch (InterruptedException e) {
-
- e.printStackTrace();
- }
- person td = new person();
- Thread td1=new Thread(td);
- Thread td2=new Thread(td);
- Thread td3=new Thread(td);
- Thread td4=new Thread(td);
- Thread td5=new Thread(td);
-
-
- td1.start();
- td2.start();
- td3.start();
- td4.start();
- td5.start();
-
- }
- }
复制代码 |