. getClassLoader (),NewClass[] {Connection.class},NewConnectionhandler ()); }}The following is an example to test the operation of the simple database connection pool, simulating the process of client Connectionrunner acquiring, using, and finally releasing the connection, when it is used, the connection will increase the number of connections acquired, and conversely, will increase the number of non-acquir
threads and non-io threads do not exit until asynchronous Io operations are completed. However, it may take a long time for a non-I/O thread to initiate a request.The correct method to use the thread pool is that the work project function and all functions it will call must be thread pool safe. Secure functions should not assume that the thread is a one-time thread or a permanent thread. Generally, asynchr
"Java concurrency" executor framework mechanism and thread pool configuration usage
One, executor frameworkThe executor framework, introduced in Java 5, uses a thread pool mechanism that simplifies concurrent programming operations by controlling the start, execution, and shutdown of threads under the Java.util.cocurrent package. Therefore, after Java 5, booting a thread through executor is better, more ma
interface, the final implementation is implemented by the database-driven provider, considering just an example, we construct a connection through a dynamic proxy, and the proxy implementation of the connection is simply a commit () Hibernate 100 milliseconds when method calls
public class Connectiondriver {
static class Connectionhandler implements invocationhandler{
@Override
public object invoke (object proxy, Method method, object[] args) throws Throwable {
i
Database Connection Pool, database connection pool java
I. Why should I use the database connection pool?
Database Connection resources are very expensive, especially when accessing the database through the network. A simple physical connection causes low performance.
Therefore, the concept of database connection
is Poolid5, pools/0All poolid and their corresponding emysqlconnmgrprocessid in the current system6, CONNS_FOR_POOL/1All links in the corresponding pool are obtained according to Poolid, and the input parameter is PoolidAdd_pool/2The ADD_POOL/2 function primarily calls the SUPERVISOR:START_CHILD/2 function to add emysql_conn_mgr gen_server processes under the EMYSQL_CONN_POOL_SUP monitoring tree.Code snippet for Emysql_conn_pool_sup module:1 start_li
your needs,If your application has no requirements for the secure transaction mechanism, you must use the thread pool and Object pool technology to obtain the best performance..
Therefore, based on the principles of servler and EJB, we can plan our application, what can be put in servlet, or what needs to be implemented in EJB:
The nature of the thread determines that servlet is only suitable for some
the above two "possible". The task may be executed, and the impossible situation is that the above scenario is 3; it may not be done immediately, because the task may also be queued in the queue, so it is still waiting for the allocation thread to execute. Knowing the literal question, let's look at the concrete implementation.public void Execute (Runnable command) {if (command = = null)throw new NullPointerException ();if (poolsize >= corepoolsize | |!addifundercorepoolsize (command)) {if (run
may be executed, which is not possible in case 3 described above; it may not be executed immediately because the task may still be queued in the queue, so it is still waiting for the allocation thread to execute. After understanding the literal problems, let's take a look at the specific implementation.
Public void execute (Runnable command ){If (command = null)Throw new NullPointerException ();If (poolSize> = corePoolSize |! AddIfUnderCorePoolSize (command )){If (runState = RUNNING workQueue.
) {returnC ~capacity;}Private Static intWorkercountof (intc) {returnC capacity;}Private Static intCtlof (intRsintWC) {returnRS | wc }Description :A CTL is an atomic object of type Atomicinteger. The CTL Records 2 information about the number of tasks in the thread pool and the thread pooling status.The CTL consists of 32 bits in total. Where the high 3 bits represent the thread pool state, and the low 29 b
scheduling Thread Pool
It is also relatively simple to use the thread pool. You only need to submit a "task" to the thread pool. Generally, the object. submit method is used as follows:
① ThreadPool. submit (Callable
Like the Runnable interface, Callable automatically calls the call method in the interface. Unlike t
Simple IntroductionThe string Chang in Java is a pool of strings stored in the Java heap memory . We know that string is a special class in Java, and we can create a string object using the new operator, or you can create a string object with double quotation marks ("").string constant pool in Java, which clearly explains how to maintain a string constant
Java String and constant pool, JavaString constant pool
String is a string in java. The String class is unchangeable. Any change to the String class will return a new String class object.
1. First, String does not belong to eight basic data types. String is an object.
Because the default value of an object is null, the default value of String is also null, but it is a special object and has some features th
ArticleDirectory
This article briefly introduces the working principles of the database connection pool and thread pool, hoping to help you.
When the amount of data requested by the client is largeThread PoolIt can save a lot of system resources, so that more CPU time and memory can be used efficiently. WhileDatabase Connection PoolWill be greatly improvedProgramOperational Efficiency.
, there are three key points1.FactoryCallback. Used for object creation, destruction, validation, blockage prevention, etc.Configuration of 2.PoolThe parameters of the pool. For example, the maximum number of, the minimum number, the longest blockage time and so on.3.Pool instancesThe actual work.Apachecommons Pool 1.x Sample code:Package Test.ffm83.commons.pool;
Better use of JAVA thread pool and JAVA Thread Pool
This article describes the thread pool size parameters, creation of working threads, collection of Idle threads, use of blocked queues, task denial policies, and thread pool hooks. use, some details are involved, including the selection of different parameters, differ
[Switch] thread pool introduction under JUC, juc Thread Pool
IntroductionDisadvantages andJavaUse of four thread poolsWhich is also applicable to Android. This article is a basic article. Later I will share some advanced features of the thread pool.
1. disadvantages of new ThreadDo you still have the following new Thread to execute an asynchronous task?
new Threa
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.