package com.hanqi.xc; import java.util.LinkedHashSet; import java.util.Random; import java.util.Set; public class GuoShanDong implements Runnable { private static int deng=0; @Override public void run() { deng= deng+5000; try { Thread.sleep(deng); } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } System.out.println(Thread.currentThread().getName() +" 过山洞"); } public static void main(String[] args) { String ary[] ={"赵","钱","孙","李","周","吴","郑","王","冯","陈"}; GuoShanDong gsd = new GuoShanDong(); Set<Integer> set=new LinkedHashSet<Integer>(); while(true){ if(set.size() == 10){ break; } //乱序排列(随机) int a=(int) (Math.random()*10); set.add(a); } for(int b:set){ Thread th = new Thread(gsd, ary[b]); th.start(); } }
时间: 2024-10-05 15:35:01