20165208 2017-2018-2 "Java Programming" Week 8 Learning Summary

20165208 2017-2018-2 "Java Programming" Week 8 Learning Summary

Textbook learning content summary

Chapter 12

thread state

  • Create thread object
  1. Use the Thread class or subclass to create directly: Thread(Runnable target)create a thread, get the current thread object, and getName()return the name of the thread.
  2. Use Runnable interface: more flexible than Thread
  • The method of operation

    run()specifies a specific mission
  • interrupt
  • die

Common methods of threading

  • start(): Start the thread, only the newly created thread can call
  • run(): Defines the operation performed after the thread object is scheduled. It is a method that the system automatically calls and the user cannot refer to. It is necessary to create a subclass of the Thread class to override the original method.
  • sleep(int millsecond): Make high-priority ones give up cpu resources automatically
  • isAlive(): Returns false for new and dead states, and returns true when run() starts to run to the end
  • currentThread(): returns the thread that is using the cpu
  • interrupt(): Restart a sleeping thread

thread synchronization

synchronizedIf the method is modified, the synchronization mechanism must be followed when calling

thread union

join().BMake A join B, that is, A thread interrupts execution until B completes

GUI thread

GUI: Graphical user interface

mainly involves AWT-EventQueue (responsible for handling GUI events) and AWT-Windows (responsible for drawing forms or components to the desktop)

timer thread

Timer(int a,Object b)start()Create a timer, start the thread of the Timer class , stop()stop, restart()restart the recovery thread

Problems and Solving Processes in Teaching Materials Learning

Question 1: p366 mentioned that the Runnable class is more flexible than the Thread subclass when creating a thread, but I don't know how to use the Runnable class.

Solution 1: Learn from online information and learn that the class that implements the Runnable interface must use an instance of the Thread class to create a thread. Creating a thread through the Runnable interface is divided into two steps:

  1. Instantiate a class that implements the Runnable interface.
  2. Create a Thread object, and pass the object instantiated in the first step into the constructor of the Thread class as a parameter.

code hosting

Summary of last week's exam mistakes

  1. The following options are not basic features of relational databases:

    A. Different columns should have different data types

    B. Different columns should have different column names

    C. It has nothing to do with the order of the rows

    D. It has nothing to do with the order of the columns The

    correct answer is A , which is not an essential feature of relational databases
  2. The following are data manipulation languages:

    A.insert

    B.update

    C.create

    D.select

    This title is multiple choice, in addition to update, insert is also a data manipulation language

Others (perception, thinking, etc., optional)

This chapter mainly learns threads. Multithreading is one of the characteristics of Java, but it does not mean that multiple events are processed at the same time. The knowledge in this chapter is also closer to specific problems and can be used to better express and solve practical problems.

References

learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 36/36 4/4 30/30
the second week 464/500 1/5 18/48
The third week 832/1332 2/7 17/65
the fourth week 939/2271 2/9 17/65
fifth week 1163/3434 1/10 17/65
Week 6 1176/4610 1/11 15/65
Week 7 864/5474 2/12 15/80
eighth week 703/6177 2/14 15/80

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324654098&siteId=291194637