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

今天就学习课程吧!

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

The Thread class in Java

The Thread class in Java

- Let's have a look at how threads work in practice. Java has a thread class that can be used to work directly with threads, but most of the time when you're writing multi-threaded code, you'll work with obstructions rather than the thread class directly. But it's useful to know how they work so you can understand the concepts that the obstructions are using. So in this example, I have a class called Main, which just has an empty main method inside it. I want to create my own thread which I can call in this main method. So to do that, I need to create a class that extends the thread class. So I'm going to right click on this before package and I'm going to choose new and then Java class. And I'm going to call this, Thread Example. So at the top after Thread Example, I'm going to add extends thread. Now I want to override the run method. So I'm going to add an @ override annotation. And then the method I want to override…

内容