三个线程轮流打印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) 回帖