Record a face questions

1, Spring in the concept of ioc

Ioc mentioned it must be mentioned Inversion of Control and Dependency Injection

Inversion of Control: Originally we need to call the object's constructor method, manually create an object when the object is created, now, we will create the object destruction handed over spring container to do, it to create objects through reflection, after we run out of objects destroy.

Dependency injection: normal service module needs to call two or more objects to complete the business logic, when we complete our business code, only the notification method spring here need to call another object, it will be like spring examples of injection as the injection dependent objects here, waiting for us to call. Object injected three ways: constructor injection, setter injection method and interface injection

2, bena default scope

The bean has five values ​​scope (scope attribute control):

singleton: single embodiment, it is the default

prototype: multiple cases, such as let Spring take over the action struts2 of time you must configure this property

request: a request and forwards the request

session: a session scope is

globalsession: global scope is a drawing, such as a bean need to share the same time among multiple servers need this property.

The default is singleton, so the spring is a single object in the default cases

3, the concepts and the role of indexes, Mysql in the main index structure, hash indexes, and Comparative B + tree index

Index: is a data structure used to quickly access the database table or view in the data storage space required.

effect:

① reduce the data retrieval time

② to ensure the uniqueness of data

Table ③ table before referential integrity

④ reduces the packet, the retrieval time ordering

(1),INDEX(普通索引):ALTER TABLE 'table_name' ADD INDEX index_name('col')

The most basic index, without any restrictions

(2),UNIQUE(唯一索引):ALTER TABLE 'table_name' ADD UNIQUE('col')

And "general index" similar, is different: the value of the index columns must be unique, but allow free value.

(3),PRIMARY KEY(主键索引):ALTER TABLE 'table_name' ADD PRIMARY KEY('col')

Is a special unique index, does not allow nulls.

(4), FULLTEXT (full-text indexing): ALTER TABLE 'table_name' ADD FULLTEXT ( 'col')

Only for MyISAM and InoDB, data for a larger, full-text indexing is time-consuming and space

Composite index: ALTER TABLE 'table_name' ADD INDEX index_name ( 'col1', 'col2', 'col3')

In order to further improve the efficiency of mysql can create a composite index, follow the "most left-prefix" principle. Creating composite index should be the most common (frequency) limitations do a column on the left, once decremented. Composite index used in the left-most field can be used in the index. Equivalent to the establishment of col1, col1col2, col1col2col3 three indexes

After indexing queries will be faster, increasing the data, delete, change operations will be slower

hash index: quickly query a record, because the distribution of the hash hash structure, and the key - the value corresponds. But it also should not be used for this range queries and sorting

B + tree index: B + Tree index data are all in the leaf nodes, and increases the sequential access pointers, each node has a pointer to the adjacent leaf leaf node. This is done to improve the efficiency range, for example, the query for all data records from the key 18 to 49, 18 when they are found, as long as the nodes and along the order of the pointers can be traversed in order to have access to all the data nodes, greatly improves the range query efficiency.

4, thread creation mode, frame thread, the thread pool concept, thread pool What? What are the thread pool thread pool plant type? Thread pool parameters

(1), inheritance Thread class

(2), implement Runnable

(3), to achieve Callable Thread line interface to create a wrapper by FutureTask

(4) using ExecutorService, Callable, Future achieve that return results thread

 Multithreading framework Executor, introduced after jdk1.5

Thread pool is a thread usage patterns, which frequently use thread creation and destruction and resource consumption in order to reduce costs brought about.
By creating a certain number of threads, so they are always ready to wait for the arrival of new tasks, but after the end of the mandate to continue to come back again on standby.

This is the core of the thread pool design ideas, " multiplexing thread creation and destruction overhead costs amortized thread ."

Compared to a task to create a thread way, the advantages of using the thread pool is reflected in the following points:

(1), to avoid duplication and overhead to create a thread to bring the cost of resource consumption

(2) to enhance the response speed of the task, the task to the direct election of a thread execution without waiting for thread creation

(3), unified allocation and thread management, but also facilitate unified monitoring and tuning

Achieve thread pool to achieve the inherently asynchronous task interface that allows you to submit multiple tasks to the thread pool thread pool thread is responsible for the choice of scheduling tasks.

Java provides four thread pool by Executors, respectively:

[ newFixedThreadPool()方法 ]

This method returns a fixed number of threads in the thread pool. The number of threads in the thread pool is always the same, when there is a new task submission, if the thread pool idle threads, it is executed immediately.

If there is no idle thread, the new task will be temporarily stored in a task queue, there is a thread to be idle, it handles tasks in the task queue.

[NewSingleThreadExecutor () 方法]

This method returns only one thread of the thread pool.

If more than one multi-task is submitted to the thread pool, the task will be saved in a task queue until the thread is idle, first-in first-out order to perform tasks.

[ newCachedThreadPool()方法 ]

This method returns a can adjust the number of threads with the actual situation of the thread pool, uncertain number of threads in the thread pool , but if idle threads can be reused, will have priority use of the thread can be reused. If all the threads are at work, there are new tasks submit new site processing task is created. All threads in the current task is finished, it will return to the thread pool multiplex.

[NewSingleThreadScheduledExecutor () 方法]

This method returns a ScheduleExecutorService objects, thread pool size is 1 .

ScheduleExecutorService interfaces on the interface ExecutorService expanded in performing a task at a given time function, such as: a fixed delay after the execution, or periodically perform a task.

newScheduleThreadPool()方法 ]

This method returns a ScheduleExecutorService object, but the thread pool can specify the number of threads .

int corePoolSize
number of kernel threads, the thread pool will ensure long-term survival of these threads in the state, even if the thread has been idle. Unless configured allowCoreThreadTimeOut will not ensure long-term survival in the thread pool, destroyed more than keepAliveTime after being idle.

int maximumPoolSize
thread pool maximum number of threads in the thread pool maintenance shall not exceed the amount is greater than the number of threads to write off less than the maximum number of threads in the thread will be destroyed after being idle for more than keepAliveTime.

long keepAliveTime
ensure the survival time, if the number of threads than corePoolSize, thread idle for more than a guarantee survival time, the thread will be destroyed. Further it refers to a keep-alive unit time units.

BlockingQueue workQueue
blocking queue storage tasks awaiting execution, the thread taken from workQueue task, the task will be blocked if no waiting. It can be passed to limit the size of the queue or infinite capacity expansion queue.

ThreadFactory threadFactory
create a thread factory.

RejectedExecutionHandler handler
rejects the request processor and the processed thread pool queue full.

Guess you like

Origin www.cnblogs.com/lm-book/p/11264770.html