0
thread ??
explain by exmple please
1 ответ
+ 6
Simply put, a thread is a program's path of execution. Most programs written today run as a single thread, causing problems when multiple events or actions need to occur at the same time. Let's say, for example, a program is not capable of drawing pictures while reading keystrokes. The program must give its full attention to the keyboard input lacking the ability to handle more than one event at a time. The ideal solution to this problem is the seamless execution of two or more sections of a program at the same time. Threads allows us to do this.The first method of creating a thread is to simply extend from the Thread class. Do this only if the class you need executed as a thread does not ever need to be extended from another class. The Thread class is defined in the package java.lang, which needs to be imported so that our classes are aware of its definition.
import java.lang.*;
public class Counter extends Thread
{
public void run()
{
....
}
}
The above example creates a new class Counter that extends the Thread class and overrides the Thread.run() method for its own implementation.
for more:
https://www.javaworld.com/article/2077138/java-concurrency/introduction-to-java-threads.html