Yesterday, we recorded the following:
1. What is the HTTP request lifecycle?
Take Tomcat + Servlet as an example.
Brief background:
1) servlet is configured in Web. xml. Each servlet is bound to a specified URL pattern.
2) servlet needs to implement the corresponding HTTP request processing methods, such as post corresponding to dopost, get corresponding to doget, head corresponding to dohead, etc.
3) when processing an HTTP request, you can access and modify some global variables that save the context information of the HTTP request, such as Cookie, session, request, and response.
Therefore, we can briefly summarize the following:
1) HTTP server captures HTTP requests
2) The request contains a URL. Based on the URL pattern-servlet distribution rule defined in Web. XML, the request is distributed to the specific servlet for processing.
3) The request contains some context information, such as URL-encode parameters and cookies. The request is encapsulated into the corresponding context information container object and sent as parameters to the Servlet's HTTP request processing method.
4) after the HTTP server executes the HTTP request processing method defined in the servlet, it constructs a response HTTP packet based on the changed context information and reports it to the client.
The expressions you have come up with may be nonstandard, but the general process is correct.
2. multi-thread Reader/Writer Problem: there is now a queue, the first line is out of the queue, and the end is appended. There is one writer thread and four reader threads. How can we ensure operation correctness? Write out JavaCode.
Typical semaphore P/V Operation Problems: The Reader/writer uses two semaphores for full/empty synchronization, and the reader obtains queue operations through mutex to ensure the correctness of Column Operations. For more information, see operating system related books.
Java provides the semaphore class, which is located in the Java. util. Concurrent package. C/C ++ can use the sem_wait and sem_post methods.
Other problems are relatively difficult, so I will not write them here.
Note: Go to the end of HR and go to the city again in the afternoon.