Preparing for an interview two

1, the difference between thread and start the run?
    run () method is equivalent to the task processing logic entry thread, it is called directly by the Java virtual machine runs the corresponding thread
    start () role is to start the corresponding thread, the thread into the ready state, start () call does not mean the end corresponding thread has been running, the thread may run later, or may never run.
2, Can not by start () method, directly call run () method do?
    Yes, if the calling thread class directly run () method, it will be treated as an ordinary function call;
      Start () method can be called run () method asynchronously, but directly call run () method does synchronization can not purpose multi-threaded.
3, the emergence of cross-domain and solve
    cross-domain refers to want to get a page b page resources, if a. b agreement page, domain names, or different ports is a page that ip address, b page for the domain name address, access operations are carried out across domains, and the browser for security issues generally restrict cross-domain access, that is not allow cross-domain requests resources.
    Solution: JSONP, the request path turn into jsonp format, then the request
    achieved JSONP to: create a callback function, and then call this function on a remote server and JSON data format passed as parameters, completion callback, the JSON data filled into Callback.
    SpringBoot cross-domain solution: On the Controller plus @CrossOrigin (see next best principle)
    @CrossOrigin (Origins = "*", maxAge = 3600) // Origin = "*" on behalf of all domain name is accessible
// maxAge before flight maximum age cache duration of response is simply Cookie valid (in seconds)
4, when the difference between the GC garbage System.gc () and finalize () are
    collected and delete unreferenced objects. By "System.gc ()" to trigger garbage collection, but does not guarantee does garbage collection.
    JVM's garbage collection only those objects created by the new keyword, so. If the object is not to create a new use, you can use the function to finalize the implementation process.
5, Java objects created in several ways?
    1. Using the new keyword, such as: Student Student = new Student ();
    2. Using the newInstance method of class Class, this method calls newInstance no argument constructor Create Object: Student Student.class.newInstance STU = ();
    . 3 using the newInstance method of class Constructor, java.lang.relect.Constructor class also has a newInstance method to create objects. We can call by this method has a parameter of newInstance and private constructor, in fact, inside the Class newInstance method calls newInstance method of the Constructor: Student STU = Constructor.newInstance ();
    4, use the Clone method: To use the clone method, we must implement the Cloneable interface and implement a clone method of its definition. Such as: Student STU2 = <Student> stu.clone ();
6, lost halfway down and MQ messaging solution?
    1. The server is lost: the memory of the message persistence, were obtained from the serialized file when you restart mq
    2. The client is missing: the user sent the message is still the cache, mq can re the Read
7, request in several ways?
    1.GET: Request page information specified, and returns the entity body
    2.POST: requests the server to accept the specified document as a new subordinate entities identified by the URI
    2.HEAD: only request header page
    3.DELETE: Request server to delete the specified page
    4.COPY: the server will request the specified page to another web address
    5.LINK: requests the server to establish the connection relationship
    6.UNLLINK: disconnect relations
8, volatile lightweight, can only modify variables. synchronized heavyweight, also modified method
9, TCP three-way handshake, before performing data transmission, and the other must establish a reliable connection
    1. The client sends a request to inform the background
    2. Background to respond to client can establish a connection
    3. The client checks the connection flag, correct connection is established with the server, the subsequent data transfer starts
10, UDP protocol user data transport layer protocol is a connectionless transport protocol stateless; advantage is fast, requires fewer resources, there is no handshake, but unstable easily transfer data packet loss.
11, Redis underlying protocol is TCP
12, java realize how commodity spike
    the number of items put into redis, when a user after a successful purchase, synchronize the cache, the number is zero, other users can not buy.
13, Redis cache synchronization method of
    reading data time. Redis start inside the investigation, if not, go check the database, and wrote redis inside, and set the expiration time.
14, ajax transfer object, how controller receiving
    use @RequestBody annotation
    may request JSON string bound to the body by a respective bean @requestBody.
15, Java queue in
    the queue is a special linear table, delete operation is allowed only in the front section of the table (Front), only the rear end of insertion, the table (rear). End of insertion, said the team is not the end, delete operation ends become the team's head. For a queue, each element always enters from the rear end of the queue queue, then wait until after all the elements of the element out of the team, the current element to the team, follow the principle of first in first out (FIFO), and if the queue does not contain any element, it is called the queue empty queue.
    Queue provides a Java interface, and offers numerous class that implements this interface: ArrayBlockingQueue, LinkedBlockingQueue, ConcurrentLinkedQueue.
    ArrayBlockingQueue, LinkedBlockingQueue and CurrentLinkedQueue, they are thread-safe queue. LinkedBlockingQueue higher throughput, but low performance.

Guess you like

Origin www.cnblogs.com/tk970803/p/11140674.html