解决方案 »

  1.   


    数组中就存在两个网址,一个不能访问,一个可以访问,不存在你说的那种情况。
    按照你的说法,不会出现意外,一定是一个能访问,一个不能访问,在不考虑请求时间的情况下,如下,“a”能访问,其他的不能访问:public static int time = 0;
    public static void main(String[] args){
    String[] url = {"ddd","a"};
    boolean wait = false;
    int u = 0;
    while(true){
    u = u%2;
    if(wait){
    wait = goon(url[u]);
    }else{
    wait = go(url[u]);
    }
    u++;
    }
    }

    public static boolean go(String s){
    for(int i=0;i<3;i++){
    time++;
    if(request(s)){
    System.out.println("第"+time+"秒访问"+s+"成功" );
    try{
    Thread.sleep(1000);
    }catch (Exception e) {}
    return false;
    }
    System.out.println("第"+time+"秒访问失败" );
    try{
    Thread.sleep(1000);
    }catch (Exception e) {}
    }
    return true;
    }

    public static boolean goon(String s){
    for(int i=0;i<10;i++){
    time++;
    if(request(s)){
    System.out.println("第"+time+"秒访问"+s+"成功" );
    try{
    Thread.sleep(1000);
    }catch (Exception e) {}
    }
    }
    return false;
    }

    public static boolean request(String s){
    return s.equals("a");
    //请求方法
    }