The thread pool is to create a certain number of threads in advance, and then when an asynchronous task is needed, the thread pool automatically takes the task in the queue, and automatically takes the next task each time a task is completed.This article provides a simple thread pool, so it does not provide the ability
understand idea, the code needs to be explained in detail.
A thread pool, a task queue, should have no comments;
Task queue is a typical producer-consumer model, this model requires at least two tools: a mutex + a conditional variable, or a mutex + a semaphore. A mutex is actually a lock that guarantees the addition and removal (acquisition) of the mutex, and a condition variable is a guarantee of the synchronization of the Get task: An
terminated after they have survived for a certain period of time. The time to live is one minute. This is to be distinguished from the fixedthreadpool.The number of threads in the Scheduledthreadpool thread pool also needs to be pre-specified, and its main feature is that queue tasks are read and executed on a scheduled delayNo matter what thread, when the task queue increases the speed of the queue read execution, it is possible to create a task los
This is a simple application of the pthread thread
1. Implements the concept of thread pool, which can be reused by threads.2. The signal volume, mutual exclusion lock, etc. encapsulation, business processing function only need to write and business-related code.3. Good portability. If you want to apply this thread pool code to your implementation, just write yo
connection pool is the long-connected MySQL mode, will keep the connection with MySQL, reuse the connection for MySQL operation, thus saving the establishment of connection and disconnection consumption.Why can I reduce the number of data connections?The connection pool is maintained for several long connections, and when a new request arrives, if the connection pool
than DBCP. World Mainstream framework: Spring Framework, Hibernate framework InteriorThe C3P0 connection pool is used.In accordance with this principle, I wrote a simple database connection pool, not considered very comprehensive, for reference only, interested friends can define a more logical connection pool.First write a configuration file that writes informa
Myicq 1.0 implements a memory pool model that can automatically allocate and recycle object memory. The following describes the implementation method.
First, the memory pool uses a two-way linked list. The implementation of the linked list is a common list_head form in Linux, but it is implemented by itself.
A bit puzzled: Since list_head is used, if it is implemented in Linux, you can call the list_head b
after c3p0: PackageCn.itcast.jdbc;Importjava.sql.Connection;Importjava.sql.SQLException;ImportJavax.sql.DataSource;ImportCom.mchange.v2.c3p0.ComboPooledDataSource; Public classJdbcutils {/** configuration file for Demon person configuration! Ask you to give c3p0-config. xnl! */ Private StaticCombopooleddatasource datasource=NewCombopooleddatasource (); /*** Use connection pooling to return a connection object *@return * @throwsSQLException*/ Public StaticConnection getconnection
DemandPreviously written a C # version of the simple thread pool http://blog.csdn.net/ylbs110/article/details/51224979Having just learned the future of the new c++11 feature, I thought of using it to implement a thread pool.ImplementThe main difference between the basic and C # versions is the implementation of the delegate, the different threading handles, and the thread Lock:
Originally C + + has
Create a thread pool: A few thread pools that are more commonly used1 "NewcachedthreadpoolThis is a pool of cache threads. Create a thread pool that will reclaim threads if there are idle threads present, and if the thread is not enough, create a new thread2 "NewfixedthreadpoolInitializing a fixed-length thread pool,
distributed on a "as is" BASIS, without warranties or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -The contents of this file is loaded for each Web application -Context> Default set of monitored resources. If One of these changes, the - Web application would be reloaded. - Watchedresource>Web-inf/web.xmlWatchedresource> Watchedresource>${catalina.base}/conf/web.xmlWatchedresou
A simple Erlang process pool Analysis
This is a simple Erlang process pool analysis, which islearn you some erlang for Great GoodHere is an example. For details, go to the official website!Main Flowchart
Implementation Principle
The implementation principles of this example are described in detail on the official websi
Spring boot is a simple configuration method for configuring MySQL database connection, Hikari connection pool, and Mybatis.
This method is simple and supports MySQL database multi-database connection, Hikari connection pool, and MyBatis (including Dao and xml file location configuration ).
1. Introduce dependency in p
0, DBCP Introduction DBCP Database connection pool is a Java Connection pool project on Apache. DBCP the connection pool in advance with the database to establish some connections in memory (that is, the connection pool), the application needs to establish a database connection directly to the slave
Link: click here~~Test instructionsNumber of sinks time limit: theMs | Memory Limit:65535KB Difficulty:4
Describe
Nanyang Polytechnic Campus There are some rivers and some lakes, now, we think of them as a pool, suppose there is a map of our school, this map only to identify whether this is a pool, now, your task came, please use the computer to calculate the total number of pools
. Summary
The test results are as follows:
The result indicates that when the work child thread is doing task processing (SLEEP10 simulation), pushing the new work task does not interrupt the current task, but is awakened by other idle threads;
At the same time when the exit signal is issued, because the program to wait for the current task after the end of the exit, so there is a certain delay;
Reference articles:
[1] C language to implement a simple
For the bottom of the method in the multi-threaded environment Why to lock, my experience is as follows:ThreadPoolPublic synchronized static ThreadPool getinstance ()The thread pool is a singleton, and if not locked, it is highly likely that multiple instances will be createdprotected synchronized void Repool (PThread repoolingthread)This method is to put the idle thread back into the queue: if it is not locked, it is very likely that the other thread
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.