20165312 2017-2018-2 "Java Programming" 8th Week study Summary

Source: Internet
Author: User
Tags thread class time in milliseconds

20165312 2017-2018-2 "Java Program Design" 8th Week study summary of the first and 12th chapters of knowledge points
  • Processes and Threads
    • A process is a dynamic execution process of a program that corresponds to a complete process from code loading to execution to completion.
    • A thread is not a process, and during its execution, a process produces multiple threads that can share code and data in the process.
    • No process, no threads.
  • Multithreading
    • Multithreading is the case where there are several actuators in an application that work together according to several different execution threads.
    • A computer can execute only one of several threads, and the Java Virtual machine quickly switches control from one thread to another.
    • The JVM waits until all the threads in the Java application end before ending the Java application
  • The state and life cycle of a thread
    • new : When an object of the thread class or its subclasses is declared and created, the thread object is in a new state with the corresponding memory space and other resources
    • Run : Call start() method to queue and invoke run() method to execute immediately
    • Interrupt
    • death : A normal running thread completes all of his work properly or is prematurely forced to terminate,
  • The thread Scheduler in Java is responsible for managing threads, and the priority of threads is setPriority(int grade) adjusted by methods.
  • Thread class and the creation of its subclasses and threads
    • When you write a subclass of the thread class, you need to override the run() method
    • Thread creation threads typically use construction methods:Thread(Runnable target)
  • The relationship of the target object to the thread
    • Target object and thread are fully decoupled: the target object usually needs to get the name of the threadString name = Thread.currentThread().getName();
    • Target object composition thread (weakly coupled): The target object usually needs to get a reference to the threadThread.currentThread();
  • Common Methods of threading
    • start()
    • run()
    • sleep(int millsecond)The parameter millsecond is the sleep time in milliseconds, and if the thread is interrupted during hibernation, the JVM throws a Interruptedexception exception
    • isAlive()Returns TRUE or False
    • currentThread()A class method in the thread class that can be called with the class name
    • interrupt()Waking a dormant thread
  • Thread synchronization
    • Thread synchronization: A synchronized method is required for several threads
    • Thread synchronization mechanism: When a thread a uses the synchronous method, other threads must wait for it when they want to use the synchronization method
  • Thread FederationB.join();
  • Timer thread Timer(int a,Object b) creates a timer
  • Daemon Thread: thread.setDaemon(true) You can set yourself as a daemon thread
Ii. Summary of the wrong questions
    • The following belong to the common database is ()

A. Access

B. Xammp

C. Mysql

D. Oracle

E. SQL Server

Answer: ACDE (XAMPP (Apache+mysql+php+perl) is a powerful building-station integration package. )

    • Interface rowset inherits the interface __ and can call the method __ in rowset to populate its data area. ( )
      ①statement②resultset③update④populate

A. ①③

B. ①④

C. ②③

D. ②④

Answer: C

    • The type returned by the executeupdate is int, meaning that the record is affected ()

A. True

B. False

Answer: A

Iii. problems encountered this week and how to resolve them
    • In doing this week's test, set up the database and the table, run the program is not correct, repeatedly check the code is not a problem, and finally found that the database is not connected to the first, made a special silly error, almost over the test time, time is very urgent there is no ...
    • In the 12th chapter of the code, the following GUI thread, timer thread and application example used in the Nineth chapter of the content, some can not understand. Looking back at the Nineth chapter of the content, the feeling still did not understand thoroughly, and so I put the Nineth chapter system after reading the code again to see it again, so understand a bit more profound it.
    • Do not know why, to the code cloud upload code once again a problem. The problem is "update is denied, the latest commit of the current branch is behind its corresponding remote branch", as follows

!

Workaround:

(1)$ git fetch origin

!

(2) Ctrl+x

(3)$ git push origin master

Reference: Update is rejected because the latest commit of your current branch is behind its corresponding remote branch

    • This week's test topic is not deep understanding of the daemon thread, and then found on the Internet to find information about the Guardian thread.

(1) Converting a thread to a daemon can be done by invoking the thread object's setDaemon(true) method

(2) thread.setDaemon(true) must be thread.start() set before, otherwise it will run out a illegalthreadstateexception exception. You cannot set a running regular thread as a daemon thread.

(3) The new thread generated in the daemon thread is also daemon.

(4) The daemon should never access an intrinsic resource, such as a file or a database, because it will be interrupted at any time, even in the middle of an operation.

Reference: Daemon thread (Daemon thread)

Code hosting this week code

20165312 2017-2018-2 "Java Programming" 8th 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.