课程: Java: Advanced Concepts for High-Performance Development

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using the ExecutorService in Java

Using the ExecutorService in Java

- [Instructor] Now we've seen how we can create and manage threads using the thread class directly. However, in a real production system, it's unlikely that we'll want to specifically create individual threads like this. Here it's quite easy to keep track of the different threads, because there's only two of them, but in a large application, it does get more difficult. For example, we might want to reuse threads, because it uses a lot of memory to keep creating and removing them. Luckily, rather than configuring all this ourselves, Java provides some instructions that make it easier to work with threads. One good way to manage threads is to use something called an ExecutorService. So let's have a look at how to do that. So inside this main class, in the main method, at the bottom, I'm going to create a new variable of type ExecutorService. And IntelliJ has added the Java dot tool, dot concurrence dot executive service…

内容