201671010130 2016-2017-2 "Java Programming" 17th Week study Summary

Source: Internet
Author: User
Tags thread class

Threading Learning Summary :

    • thread is a single execution stream
    • The difference between program one and program two is that when a program has an action, the user's operation will be queued, can not run at the same time two actions, program two can also be realized the concurrency of the program.
    • New thread has two methods: 1. Implemented with an interface. 2. Inherit the thread class.
    •   broken thread: The last statement was executed or an exception was caught during execution. The thread terminates, giving the CPU the right to use.
    • The state of the thread is 7 see P635 need to be aware of the relationship between each state, You can change the state of a thread when you call any method. (thread state implements thread rotation using CPU)
    • getname () Get thread name getpriority () get priority
    •   competitive use CPU when the dynamic execution characteristics of threads, concurrency, the full use of resources. shared resources and competition for memory.
    • program is divided into four modules ( ball, ballcomponent,bounceframe,bounce)

from Ball Class (new 2d ellipse, defined Move method)

Ballcomponent Class ()

The bounce program should be queued for the user's actions, the event will respond to the next, the program serial,

The Bouncethread program, executed with thread threads, is defined as the thread, concurrency of the event response action in Addball

    • There are two ways to implement a synchronization mechanism:

1. Synchronize code blocks:
Synchronized (same data) {} same data: N thread accesses one data at the same time
2, synchronization method:
Public synchronized Data Return type method name () {}
1, objects of this class can be accessed by multiple threads safely.
2, after each thread invokes any method of the object, it will get the correct result.
3, after each thread invokes any method of the object, the object's state remains in a reasonable state.

201671010130 2016-2017-2 Java Programming 17th Week of study summary

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.