Answer the question
In order to leave comments, you need to log in
Is it necessary to declare the Thread class when creating a thread?
Task:
- to create a multi-threaded application.
Implementation method (in sequence):
1) Declare a class that will create a new thread that implements the `Runnable` interface;
2) Next, get an instance of the `Thread` type.
It looks like this:
public class One implements Runnable {
// ...объявляем переменные
// конструктор
public One(){
Thread thread = new Thread(this, "Новое имя потока");
}
}
public class One implements Runnable {
// ...объявляем переменные
// конструктор
public One(){
Thread.currentThread().setName("Новое имя потока");
}
}
Answer the question
In order to leave comments, you need to log in
In the first case, a new thread named "New thread name" will be created, executing the run method of an instance of class One. In the second case, the name of the thread that called the One constructor will be changed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question