In the last week, we learned about threads by doing lab work, threads with multiple threads and a single thread. Multithreading can perform multiple tasks at once, and you can run a thread-based program at the same time as a multithreaded program. There are two ways to build a thread, first by inheriting the thread class, and by adding the method body to the run () method to determine what action the thread is going to perform, and the second by setting the class to implement the Runnable interface and overriding the run () method. An object is set with the class that implements the Runnable interface, and a thread object is created with this Runnable object, and the threads are started using the thread object. If you need to perform a more time-consuming task, you should run the task concurrently. When the interrupt method is called on a thread, the interrupt state of the thread is set, which is the Boolean flag that each thread has. Each thread should check this flag from time to time to determine if the thread has been interrupted. Each thread has a priority and can use the SetPriority method to increase or decrease the priority of any one thread. Multi-threaded scheduling assigns threads by priority. Use the Sleep method to determine the sleep time of a thread. It can also be used to execute multiple threads at the same time. A try catch statement is required to write a thread. The knowledge points were learned by doing experimental tasks.
2016-2017-2 "Java Programming" 16th Week study Summary