java in a variety of pool

Constant pool, thread pool, connection pool

First, the constant pool
1, what is constant

Is a value that itself 

For example: Eight elementary data type string plus

Variables can not change, the final modified

E.g. final int i = 1;

        String str="hello";

2, the role of

In order to avoid frequent create and destroy objects affect system performance to achieve a shared object

 

 

Second, the thread pool
ThreadPool

Role: to limit the number of execution threads in the system

Understand: in the system environment can be automatically or manually set the number of threads, to achieve the best operating results, less waste of system resources, and more systematic obstruction.

        Thread pool controls the number of threads, other threads queue. A task is completed, taken from the top of the task execution queue. If the queue does not wait for the process, the thread pool is waiting. When a new task to run, if there is to wait for the thread pool threads started running, otherwise enter the queue.

 

What is the role thread pool?

Thread pool function is to limit the number of execution threads in the system.

1, to improve the efficiency created a certain number of threads in the pool, and so need to use the time to get from a pool this time than needed to create a thread object much faster.

2, to facilitate the management can write a thread pool thread management code for the same pool of management, for example, there is the program to create 100 threads at startup, whenever there is a request to allocate a thread to work, if there happens to concurrent 101 requests that the extra which a request can be queued, create a thread to avoid endless cause the system to crash.

 

Third, the pool is connected
to a database connected to reuse, to improve the performance and response time to the request of the server, using a database connection pool.

A plurality of pre-established connection pool database connection object, and then save the connection object is connected to the pool, when the client request arrives, a connection object taken from the pool to service the client, when the request is completed, the client calls the close () method , the connection object back into the pool.

Guess you like

Origin www.cnblogs.com/xinghaonan/p/11953826.html