首页 > 字节跳动机试算法三个线程轮流打印1-100
头像
冰雪俊构
发布于 2021-05-25 11:03
+ 关注

字节跳动机试算法三个线程轮流打印1-100

三个线程轮流打印1-100
public void TestLoading() {

        long start_tick = SystemClock.elapsedRealtime();

        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                long my_tick = SystemClock.elapsedRealtime() - start_tick;
                while (my_tick <= 100000) {
                    my_tick = SystemClock.elapsedRealtime() - start_tick;
                    if (my_tick > 1000) {
                        Log.e("jun", "thread 111111111  print  " + my_tick / 1000);
                        SystemClock.sleep(3000);
                    }

                }

            }
        });
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                long my_tick = SystemClock.elapsedRealtime() - start_tick;
                while (my_tick <= 100000) {
                    my_tick = SystemClock.elapsedRealtime() - start_tick;
                    if (my_tick > 2000) {
                        Log.e("jun", "thread 22222222  print  " + my_tick / 1000);
                        SystemClock.sleep(3000);
                    }

                }
            }
        });
        Thread thread3 = new Thread(new Runnable() {
            @Override
            public void run() {
                long my_tick = SystemClock.elapsedRealtime() - start_tick;
                while (my_tick <= 100000) {
                    my_tick = SystemClock.elapsedRealtime() - start_tick;
                    if (my_tick > 3000) {
                        Log.e("jun", "thread 33333333  print  " + my_tick / 1000);
                        SystemClock.sleep(3000);
                    }

                }
            }
        });
        thread1.start();
        thread2.start();
        thread3.start();
}




全部评论

(0) 回帖
加载中...
话题 回帖

推荐话题

相关热帖

近期热帖

近期精华帖

热门推荐