1.Spring configures four types of data sources

Spring’s built-in datasource (DriverManagerDataSource), DBCP, C3P0, and JNDI datasource.

1.1. Spring’s built-in data source

 

DriverManagerDataSource

XML code:

[html] view plain copy print?

 <</B> bean id=”dataSource” 

 class=”org.springframework.jdbc.datasource.DriverManagerDataSource” > 

 <</B> property name=”driverClassName” value=”oracle.jdbc.driver.OracleDriver” /> 

< Property name=” URL “value=” JDBC: Oracle :thin:@172.19.34.6:1521:ORCL” />

 <</B> property name=”username” value=”orclight” /> 

 <</B> property name=”password” value=”123456″ /> 

 </</B> bean > 

1.4. The JNDI data source

If the application is configured on a high-performance application server (such as WebLogic or Websphere, Tomcat, etc.), we may prefer to use the data source provided by the application server itself. The application server’s data source is used by the JNDI open caller, and Spring specifically provides a JndiObjectFactoryBean class that references JNDI resources for this purpose.

XML code:

[html] view plain copy print?

 id=”dataSource” class=”org.springframework.jndi.JndiObjectFactoryBean”

 name=”jndiName” value=”java:comp/env/jdbc/orclight” /> 

  

     

              

 

[html] view plain copy print?

Xmlns=www.springframework.org/schema/bean…

Xmlns:xsi=www.w3.org/2001/XMLSch…

 xmlns:jee=www.springframework.org/schema/jee

Xsi: schemaLocation = “HTTP: / / www.springframework.org/schema/bean…

www.springframework.org/schema/bean…

 www.springframework.org/schema/jee

www.springframework.org/schema/jee/…” >

 id=”dataSource” jndi-name=” java:comp/env/jdbc/orclight” /> 

  

2. What is the use of Spring?

The IOC container actively injects its dependency classes into an object when it instantiates it.

The relationship between objects (module to module) is not related by code, but is managed by configuring class specifications (Spring internally assembles objects by reflection)

Aop can use Aop to isolate each part of the business logic, so that the coupling degree between each part of the business logic is reduced, improve the reusability of the program, and improve the efficiency of development.

 

3. Connect to the database

Indicates that the join result contains only rows that meet the join condition. Both tables participating in the join should meet the join condition.

4. Difference between hashTable and hashMap

 

HashMap is a lightweight (non-thread-safe) implementation of Hashtable, both of which implement the Map interface, primarily

The difference is that HashMap allows null keys, which can be more efficient than Hashtable because it is not thread-safe.

A HashMap allows NULL as an entry key or value, whereas a Hashtable does not.

HashMap contains containsValue and containsKey. Because the contains

The method is misleading.

Hashtable inherits from the Dictionary class, and HashMap is an implementation of the Map interface introduced in Java1.2.

The main difference is that the Hashtable method is Synchronize, whereas HashMap is not, and is accessed on multiple threads

When Hashtable is used, it does not need to synchronize its methods itself, whereas a HashMap must provide external synchronization for them.

A Hashtable and a HashMap use roughly the same hash/ Rehash algorithm, so there won’t be much difference in performance.

 

One convenient way to do this is to use the Collections class’s static synchronizedMap() method, which creates a thread-safe Map object and returns it as a wrapped object. Methods on this object give you synchronous access to the underlying HashMap. The upshot of this is that you can’t break synchronization in a Hashtable when you don’t need it (such as in a single-threaded application), and synchronization adds a lot of processing overhead.

5. Load balancing

 

Load balancing is a server set composed of multiple servers in a symmetric way. Each server has equivalent status and can provide services independently without the assistance of other servers.

Through some load balancing technology, requests from the outside are evenly distributed to a server in a symmetrical structure, and the server receiving the request responds to the client’s request independently. Load balancing can evenly distribute customer requests to the server array to provide rapid access to important data and solve the problem of large number of concurrent access services.

 

Based on the existing network structure, load balancing provides a cheap, effective and transparent method to expand the bandwidth of network devices and servers, increase the throughput, strengthen the network data processing capacity, and improve the flexibility and availability of the network.

 

6. Concurrent

Concurrency and parallelism are both macroscopically related to processing multiple requests simultaneously. But concurrency is different from parallelism. Parallelism means that two or more events happen at the same time. Concurrency is when two or more events occur at the same time interval.

Concurrency can be understood as the maximum number of sessions maintained by the server, whereas parallelism is different. It is related to how many sessions are running at the same time. If there are two servers (processes), the number of concurrent sessions is 2 and the number of concurrent sessions is 1000. We can also compare the concepts of throughput and bandwidth.

 

Throughput vs. bandwidth: Throughput and bandwidth are confusing terms, both measured in Mbps. Let’s first look at the corresponding English, throughput: throughput; Bandwidth: Max net bitrate. When talking about the bandwidth of a communication link, it generally refers to the number of bits per second that can be transmitted over the link. It depends on the link clock rate and channel coding, also known as line speed in computer networks. You can say that Ethernet has a bandwidth of 10Mbps. But you need to distinguish between the available bandwidth (bandwidth) on the link and the number of bits per second (throughput) that can be transmitted on the actual link. The term “throughput” is often preferred to describe the test performance of a system. Thus, a pair of nodes connected by a link with a bandwidth of 10Mbps May only achieve a throughput of 2Mbps because the implementation is subject to various inefficiencies. This means that applications on one host can send data at 2Mbps to another host.

 

 

Bandwidth can be understood as parallel, that is, 10M bits (0,1) can be transmitted in the line at the same time. Throughput is similar to concurrency, meaning that the host can process 2M bits per second. Some metaphors are not very appropriate, but take a look, there are some similarities.

 

7.Filter, Servlet, Listener

7.1. The Filter

Implement javax.servlet.Filter interface, configure and label in web.xml to specify which Filter implementation class to Filter which URL links. Initialization occurs only when the Web is started.

 

The filter flow is linear. After the URL is sent and checked, the original flow can be kept going down and received by the next filter, servlet, etc., and the servlet processes it

After, it does not pass down. The Filter function can be used to keep the process going as it was, or to dominate the process, whereas the servlet function is mainly used to dominate the process.

Features: You can modify the headers of Request and Response before responding to a Request. You can only forward a Request but cannot send a Response directly. Filter can be used to filter character codes and detect users

Whether to log in filtering, prohibit page caching and so on

 

7.2. The Servlet

The servlet process is short; once the URL is passed in, it is processed, and then returned or diverted to some self-specified page. It is primarily used for control prior to business processing.

 

7.3. The Listener

Servlets and filters are for urls, and listeners are for object operations, such as the creation of a session, the occurrence of session.setattribute, and the occurrence of such events

Do something in life.

8.Struts2 and SpringMVC principles

 

1. Mechanism: Spring MVC’s entry point is a servlet and Struts2 is a filter, which results in a different mechanism.

 

2. Performance: Spring is slightly faster than Struts. Whereas Spring MVC is method-based design, Sturts is class-based and instantiates an action for each request, and each action is injected with properties, Spring is method-based and more granular, but with the same care as controlling data in servlets. Spring3 MVC is a method-level interception that injects request data into a method based on annotations on its parameters. In Spring3 MVC, each method corresponds to a request context. The Struts2 framework is class-level interception. Each time a request comes in, an Action is created and setter getter methods are called to inject data from the request. Struts2 actually deals with request through setter getter methods; In struts2, an Action object corresponds to a request context.

 

3. Parameter transfer: Struts is in the acceptance of parameters, you can use attributes to accept parameters, which shows that parameters are shared by multiple methods.

 

4. Design idea: Struts is more in line with OOP programming idea, while Spring is more cautious and extends on servlet.

 

5. The implementation mechanism of the Intercepter: Struts has its own interceptor mechanism, while Spring MVC uses an independent AOP approach. As a result, the configuration file size of Struts is still larger than that of Spring MVC, although the configuration of Struts can be inherited, so I think spring MVC is simpler to use and more efficient to develop. Spring MVC is method level interception, a method corresponds to a request context, and a method corresponds to a URL, so spring3 MVC is easy to implement restful urls from the architecture itself. Struts2 is class-level interception, where each class corresponds to a request context; Restful urls are tricky to implement because one struts2 action method can correspond to one URL; Its class attributes are shared by all methods, making it impossible to annotate or otherwise identify the method to which it belongs. Spring3 MVC methods are basically independent of each other. They have their own request response data. The request data is retrieved by parameters, and the processing results are returned to the framework through ModelMap. However, all Action variables are shared, which does not affect the operation of the program, but gives us trouble when coding and reading the program.

 

In addition, spring3 MVC validation is also a highlight. It supports JSR303, which makes it easy to handle Ajax requests with a @responseBody annotation and return the response text directly.