线程池SingleThreadPool
只有一个核心线程,当被占用时,其他的任务需要进入队列等待
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); for(int i = 0;i<30;i++){ final int finali = i; Runnable runnable = new Runnable() { @Override public void run() { try { Thread.sleep(2000); Log.d("Thread", "run: "+finali); } catch (InterruptedException e) { e.printStackTrace(); } } }; singleThreadExecutor.execute(runnable); } } }