20155327 Java programming Eighth week of study summary

Source: Internet
Author: User

20155327 Java programming Eighth week of study summary
Summary of learning contents of textbook
12th Chapter

Processes and Threads
Process completion: Code loading, execution until execution is complete
Threads: A process consists of multiple threads.
The process of completion of a thread: its own creation, existence, and extinction
Relationship: No process, no threads
A thread is a small thread that runs in a process.
Thread
Multithreading: The process by which several actuators execute the program together.
Note: The computer can only execute one of those threads at any given time.
Establish Multithreading: The Java Virtual machine quickly switches control from one thread to another, and these threads are executed in turn and each thread has the opportunity to use CPU resources.
Main thread: When the JVM loads code, it discovers threads that are started after the main method
The state of the thread:
New
Run: Using the Start () method
Interrupt
Death
Creation of Threads
Two different ways:
Create using the thread class subclass: The Run () method needs to be rewritten.
Using the Thread class
Construction method: Thread (runable target)
You need to create a case for the Runnable interface class and override the Run method in that interface.
Target object-to-thread relationship: Fully decoupled and target object combination threads
Common methods in Threads:
Start (): Note that using the start () method eliminates the need for the thread to call the start () method.
Run (): Rewrite run () in the thread subclass or write run () in the Runnable interface
Sleep (int millsecond): Causes the process to hibernate.
Note: The parameter millsecond is the sleep time in milliseconds
The sleep method must be called in the Try-catch statement block
4.isAlive (): Thread does not enter death state, call IsAlive () method to return True
Call the IsAlive () method to return false after a thread enters the dead state
5.currentThread (): Returns the thread that is using the CPU thread.
6.interrupt (): Unlocks the sleep state of the thread.
Thread synchronization: Several threads in a program need to use a method, and this method is decorated with synchronized.
Thread synchronization mechanism: When thread A uses the Synchronized method, other threads that want to use this synchronized method must wait until thread a finishes using the Synchronized method.
To reconcile synchronized threads:
1.wait (): Used in the synchronization method, so that the thread waits, temporarily give up the use of the CPU.
2.notifyAll (): Notifies all threads that have been waiting for this synchronization method to end the wait, and the thread that was interrupted will continue to execute the synchronization method from the point where it was just interrupted.
3.notify (): Notifies one of the waiting threads of the end of a wait.
+ + must use these three methods in the Sync method + +

Thread Federation
Join (): This method is called by other threads and can be federated with the thread that is using CPU resources.

GUI thread
Timer thread: Using the Time class
Daemon thread: Using the Void Setdaemon (Boolean on) method

Code Hosting

Last week's summary of the wrong quiz
Q1: Interface rowset inherits the interface __, you can call the method __ in rowset to populate its data area.
①statement②resultset③update④populate
A. ①③
B. ①④
C. ②③
D. ②④

A1: Positive Solution: C
Analysis: Compared with resultset,
(1) rowset extends the ResultSet interface, so you can use rowset as you would with resultset.

(2) Rowset expands the ResultSet interface, so the function is more and richer than resultset.

(3) By default, all RowSet objects are scrollable and updatable. And ResultSet is only forward scrolling and read-only.

(4) Rowset can be non-linked, while ResultSet is connected. Therefore the data can be manipulated offline using the Cacherowset interface.

(5) The rowset interface adds the JDBC API support for the JavaBeans component model. Rowset can be used as a JavaBeans component in a visual bean development environment.

(6) rowset adopted a new method of connecting the database.
Update is often used for updating data.

20155327 Java programming Eighth week of 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.