Java interview Miscellany

1. How to achieve separate read and write database
using separate read and write the database, thereby reducing the pressure on the database. MySQL deployment on multiple servers, one of which will be set as the primary database to other settings from the database, only read from the database is responsible for the operation (from passive database will be written, in order to maintain data consistency) so great to avoid loss of data but also can reduce the connection to the database, the primary database is to reduce the load on the degree of
the master copy from the embodiment
1. Replication: change master must wait slave1, slave2 ... after the completion of return
2. Asynchronous Replication: master only need to complete their own database, regardless of whether slave receive binary log (MySQL's default settings)
3. Semi-synchronous replication: master only guarantee the success of a slave operation

2. Tomcat virtual path configuration
Description: Many of my friends are very puzzled, since we all know that is deployed on Tomcat server project as long as the item packaged and put it under the webapps directory on it, why do you need to configure the virtual path? Indeed, the project into the webapps directory is very convenient, at least when you deploy a project directly to the project will be thrown into the webapps directory operations carried out easier than setting virtual path. But if you take into account the long-term nature of the operation and the number of projects it?
Set virtual path has the following three advantages:
First: We developed a project, requiring numerous changes in the version before undecided, if the deployment of test items directly to the item labeled as war package into the webapps directory, then each a version change requires a new version into the webapps directory covering the original version, so for our test project is not very trouble? If you create a virtual path, mapped directly to the original project, so that the testing phase is not very convenient? (Of course, this is to use integrated development environment tools developers can ignore);
second: Tomcat is a server, since it is a server capacity so there is not a say? Although this capacity you have the final say, but no matter how large the drive letter is not there capacity limits? If all the projects are deployed to the webapps directory, when the project is relatively large and the number of items is not the time to consider the feelings of the letter of it? Therefore, the use of virtual path can also be equipped with a partial pressure of Tomcat servers letter!
Third: multiple applications need to have different domain names, which is below talking tomcat multi-domain configuration.

  1. Modify server.xml file tomcat conf folder under under (need to restart Tomcat)

    Path: refers to the access to the web application URL entry
    docBase: worth a web application file path, it can be either absolute or a relative path
    reloadable: when reloadable = true, the relevant file changes. Tomcat stop web app and free up memory, and then loads the web app. This way eliminates the need to manually deploy web app engineering time and development tools can be used together to improve efficiency.
    crossContext: If you want to call ServletContext.getContext () within an application to return to the request dispatcher other web application running on the virtual host, set to true. It is important to false in the security environment, making getContext () always returns null. The default value is false.
    Debug: debug information and level of detail of the Logger records Engine association. The larger the number, the more detailed the output. If not specified, the default is 0.

  2. Add a profile (this method does not need to restart tomcat)
    under New / conf in the root directory of the Tomcat / Catalina / localhost / path a x.xml, and add

    to create virtual site, virtual site called x. Note docbase point to your own application directory, see method parameters for each parameter in a tag (Note that this file name as an attribute value in the path Context, regardless of the file's path property value is invalid).

3. Tomcat maximum number of connections
the way a:
Tomcat's server.xml Context element in the following parameters should be how to fit fitness


maxThreads = "150" indicates that up to handle 150 connected
minSpareThreads = "25" means that even if no one uses also open such a thread waits for long and short
maxSpareThreads = "75" means that if up to 75 threads may be empty, such as an access time of 80 people after no one visited, the tomcat does not retain 80 empty thread, but closed five empty.
acceptCount = "100" when the number of simultaneous connections reaches the maxThreads, connection line may also receive, over the return connection directly reject the connection.

The check may not enter Chinese text box
1. Implemented ime-mode CSS property text box.

2. Unicode character encoding retain only between 0 and 255.

6. The difference between the servlet and Jsp
1.jsp after compiled into a Servlet. (JSP is the essence of the Servlet, JVM java class can identify, not recognize the JSP code, Web container JSP code can be compiled into JVM java class identification)
2.jsp to exhibit better at page display, servlet logic control better at.
3.Servlet no built-in objects, Jsp through the built-in objects are objects HttpServletRequest, HttpServletResponse objects and objects obtained HttpServlet.
Jsp is a simplified Servlet using Jsp programmer needs only to complete the client to the content, how the Java script Jsp embedded into a class completed by Jsp container.
The Servlet is a complete Java classes, Service method of this class is used to generate a response to the client.

7. Database Query TOP10
MySQL database: select * from tab order by id desc limit 0, 10;

8. Join, the difference between inner join, outer of

Inner join: the result is produced 1.INNER JOIN A, B intersection (i.e. names A, B of the name of the same line)
the SELECT * the FROM TableA the INNER the JOIN TableB the ON TableA.name = TableB.name
Here Insert Picture Description

LEFT [OUTER] JOIN: generating a complete set of Table A, Table B and is matched with a value of substituted places no matching value of null.
* The FROM TableA the LEFT OUTER the SELECT TableB the JOIN the ON TableA.name = TableB.name
Here Insert Picture Description

.RIGHT [OUTER] JOIN: generating a complete set of Table B, and Table A has a value in the match, substituted places no matching value of null.
With reference to the results of FIG
FULL [OUTER] JOIN: A and B, and generating sets. For the record does not match, it will order as null values. * The FROM FULL OUTER TableA the SELECT TableB the JOIN the ON TableA.name = TableB.name
Here Insert Picture Description

9. Cookie and session difference
1.cookie data is present on the client browser, session data is stored on the server.
2.Cookie not very safe, people can analyze the local cookie store and cookie spoofing (using the user's cookies for information.)
3.Session will be stored in a certain time saved on the server. When accessing the increase would be more occupied server performance
4. single cookie stored data can not exceed 4k, many browsers are limited to one site to save up to
20 cookie.

Published 17 original articles · won praise 4 · Views 2059

Guess you like

Origin blog.csdn.net/myITliveAAA/article/details/91411362