线程池FixedThreadPool
作者:互联网
可重用线程池,只有核心线程,并发无阻塞,
public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ExecutorService fixedThreadPool = Executors.newFixedThreadPool(5); 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); Log.d("当前线程:",Thread.currentThread().getName()); } catch (InterruptedException e) { e.printStackTrace(); } } }; fixedThreadPool.execute(runnable); } } }
标签:setContentView,int,savedInstanceState,MainActivity,FixedThreadPool,线程,onCreate 来源: https://www.cnblogs.com/Ocean123123/p/10969600.html