The 8th Week of Java Programming Study summary 20165218 2017-2018-1

Source: Internet
Author: User
Tags thread class

20165218 2017-2018-1 "Java Program Design" 8th Week study Summary Textbook Learning summary Chapter 12th Java multithreading mechanism threads in Java
    • a computer can execute only one thread at any given time , and a multithreaded mechanism is a way for a Java virtual machine to quickly switch threads and make them take turns
    • ThreadThe object representing the class and its subclasses represents the thread
    • One life cycle of a thread has four states of new, running, Interrupted, dead
    • setPriority(int grade)method to adjust Thread priority
Common Methods of threading
    • start()Only new state threads can call the
    • run()Without specific content, the user program needs to create its own subclass of the thread class, overriding the run() method; after execution, the thread dies
    • sleep(int millsecond)Call causes a high-priority thread to temporarily enter hibernation; try-catch
    • isAlive()When the thread is in the new and dead state, the method returns false and is in a running state, returningtrue
    • currentThread()Returns the thread that is using CPU resources
    • interrupt()The thread used to "wake up" The method was called sleep
Thread synchronization

Using the synchronized -Modified method, you follow the synchronization mechanism: When a thread a uses the Synchronized method, other threads must wait until thread A is finished using the method.

Reconciling threads for synchronization
    • wait()Method can be executed in the thread break, temporarily let the CPU use
    • wait()Method must be notifyAll() awakened by method
    • wait()method, notify() which notifyAll() is the final method in the object class , is not allowed to be overridden
Thread Federation
//线程A在使用CPU资源的期间B.join();

A interrupts immediately until thread B finishes executing

Code Hosting

(run result of statistics.sh script)

Last week's summary of the wrong quiz
    • Wrong question 1

Connection is the class name is not a method name

    • Wrong question 2

    • ...

Resources
    • Java Learning Notes (8th Edition)

    • Java Learning Note (8th Edition) Learning Guide
    • Database Operation language

The 8th Week of Java Programming Study summary 20165218 2017-2018-1

Related Article

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.