java retry use

First met while watching ThreadPoolExecutor source usage retry, the Internet search a bit, we are experiencing (it seems everyone is seeking through the road almost ...) in the same place, and later learned to be note, too small capacity to avoid overflow the brain.

First retry keyword is not java, just one use, you can go your own name tag.

Second retry is a "transplant" out of the loop flag is used, this tag is often accompanied by recurring, they are not allowed alone. The reason that he was "transplanted" out of the loop tag, because the way he would jump out of the cycle of action to that level it is marked, just as the way out of the cycle of migration to the outside of the same.

When the start key mark layer n cycle, it will be followed when the end key role in the n-th layer.

I tidy up the usage for your reference.

  • continue

     public static void main(String[] args) {
        for (int k = 0; k < 2; k++) {
            System.out.println("第1层---"+k);
            retry_continue:
            for (int i = 0; i < 2; i++) {
                System.out.println("第1层---"+k+"第2层---"+i);
                for (int j = 0; j < 5; j++) {
                    System.out.println("第1层---"+k+"第2层---"+i+"第3层---"+j);
                    if (j == 3) {
                        System.out.println("触发标记");
                        continue retry_continue;
                    }
                }
            }
        }
    }
控制台:
第1层---0
第1层---0第2层---0
第1层---0第2层---0第3层---0
第1层---0第2层---0第3层---1
第1层---0第2层---0第3层---2
第1层---0第2层---0第3层---3
触发标记
第1层---0第2层---1
第1层---0第2层---1第3层---0
第1层---0第2层---1第3层---1
第1层---0第2层---1第3层---2
第1层---0第2层---1第3层---3
触发标记
第1层---1
第1层---1第2层---0
第1层---1第2层---0第3层---0
第1层---1第2层---0第3层---1
第1层---1第2层---0第3层---2
第1层---1第2层---0第3层---3
触发标记
第1层---1第2层---1
第1层---1第2层---1第3层---0
第1层---1第2层---1第3层---1
第1层---1第2层---1第3层---2
第1层---1第2层---1第3层---3
触发标记
  • break

    static void retryBreak(){
        for (int k = 0; k < 2; k++) {
            System.out.println("第1层---"+k);
            retry_break:
            for (int i = 0; i < 2; i++) {
                System.out.println("第1层---"+k+"第2层---"+i);
                for (int j = 0; j < 5; j++) {
                    System.out.println("第1层---"+k+"第2层---"+i+"第3层---"+j);
                    if (j == 3) {
                        System.out.println("触发标记");
                        break retry_break;
                    }
                }
            }
        }
    }
    public static void main(String[] args) {
//        retryContinue();

        retryBreak();

    }
控制台:
第1层---0
第1层---0第2层---0
第1层---0第2层---0第3层---0
第1层---0第2层---0第3层---1
第1层---0第2层---0第3层---2
第1层---0第2层---0第3层---3
触发标记
第1层---1
第1层---1第2层---0
第1层---1第2层---0第3层---0
第1层---1第2层---0第3层---1
第1层---1第2层---0第3层---2
第1层---1第2层---0第3层---3
触发标记

 

Guess you like

Origin blog.csdn.net/top_explore/article/details/95035782