2016-2017-2 "Java Programming" 16th Week study Summary

Source: Internet
Author: User
Tags thread class try catch

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.