Summary of the invention
In view of this, the purpose of the embodiment of the invention is to provide the method and apparatus of searching the connection that does not discharge in the connection pool, look for the connection leakage problem that the method for closing connection solves connection pool fast and effectively.
For realizing above-mentioned purpose, the embodiment of the invention provides following technical scheme:
A kind of method of searching the connection that does not discharge in the connection pool comprises:
After the related foundation that physical connection and user connect, the current physical connection that is in user mode is identified;
After this calls end, judge that this calls the middle physical connection of using and whether also has said sign, if confirm that then said physical connection is the physical connection that does not discharge;
The said current physical connection that is in user mode is identified is specially:
For being connected with said user to create, said physical connection connects intermediary;
With said connection intermediary records to calling in the context;
Judge whether this physical connection of calling middle use has said sign and be specially:
Check whether also have this to call the middle connection intermediary that uses in the said record.
Said method also comprises:
Remove said physical connection that does not discharge and related with between its corresponding user connects;
Deletion of physically connects the said sign that has.
After said this calls end, also comprise:
Closing that the reception client is sent connects indication;
Connect indication and remove related between said physical connection and the said user's connection based on said closing;
Deletion of physically connects the said sign that has.
Said physical connection and said user connect relatedly setting up in the following manner:
Creating one according to said physical connection is connected with the corresponding user of said physical connection;
Perhaps, connect for the related user who has existed of said physical connection.
Said physical connection is to connect the free time in the connection pool or is a newly-built physical connection of client-based connection request.
Said method also comprises:
Put into connection pool with having removed related said physical connection;
Perhaps, close the said related physical connection of having removed.
A kind of device of searching the connection that does not discharge in the connection pool comprises:
Identify unit is used for after the related foundation that physical connection and user connect, the current physical connection that is in user mode being identified;
Detecting unit is used for after calling end, detects this physical connection of calling middle use and whether also has the sign that identify unit carries out said physical connection, if having, then confirms the physical connection that does not discharge that is connected to that is detected;
Said identify unit specifically comprises:
Create subelement, be used to said physical connection and be connected establishment connection intermediary with said user;
The record subelement is used for the connection intermediary that said establishment subelement is created is carried out record.
Said device also comprises:
First releasing unit is used for after said detection goes out undelivered physical connection, removes said physical connection that does not discharge and related with between its corresponding user connects, and deletion of physically connects the said sign that has.
Said apparatus also comprises:
Receiving element is used to receive and calls closing of finishing that the back client sends and connect indication;
Said first releasing unit also is used for connecting indication and removing said physical connection and related with between its corresponding user connects according to said the closing that said receiving element receives, and deletion of physically connects the said sign that has.
Said apparatus also comprises:
Second releasing unit is used for being put back to connection pool by the physical connection of the first releasing unit disassociation or closing.
Thus it is clear that, in embodiments of the present invention, after the related foundation that physical connection and user connect, the current physical connection that is in user mode is identified; After this calls end, judge that this calls the middle physical connection of using and whether also has said sign, if; Confirm that then said physical connection is the physical connection that does not discharge; Through before calling physical connection is identified, call the back said sign inspection is look for the connection of closing, do not need artificial the participation in the whole process; Find out the connection of not closing expeditiously, solved the problem that connects leakage.
Embodiment
The embodiment of the invention provides the method and apparatus of searching the connection that does not discharge in the connection pool, below in conjunction with accompanying drawing the embodiment of the invention is described in detail.
As previously mentioned, when application program was used the connection pool technology, connection resource remained Limited resources, after therefore using, and equally need be connection closed.In the connection pool technology, introduce the user and connected this notion; Keep apart application program and physical connection; What application program was operated is that the user connects; And the operation that the user is connected can be passed on the physical connection, and the response that EIS returns through physical connection also can return to application program through user's connection.After application program uses connection, carry out the operation of closing connection, what closed this moment is exactly that the user connects, and physical connection then can be returned connection pool, rather than is closed, and gets up to supply visit next time to use with buffer memory, reaches the purpose of multiplexing physical connection.The user connects and the relation of physical connection generally is man-to-man, but under some scenes, possibly be many-to-one.
After the connection pool technology has been arranged; In the time need communicating by letter with EIS in the enterprise application, obtain physical connection from connection pool, rather than directly create a physical connection to EIS; Because the connection of connection pool is to create in advance; Therefore do not need frequent the establishment to connect, saved system resource, bring considerable improved efficiency.But the connection resource of EIS is limited, can not unconfinedly apply for, so application program is accomplished with after the operation of join dependency; Application program must be responsible for closing binding; Behind the connection closed, connection manager is just removed the user and is connected related with physical connection, and physical connection is put back to connection pool; Use for other thread, thereby reach multiplexing purpose of connecting.
The appearance of connect revealing is exactly that application program is not closed to connect after call connected is accomplished and caused, and the method for the embodiment of the invention to connect the problem of revealing and proposes in order to solve.
Referring to Fig. 1, in an embodiment of the present invention, realize that the method that the embodiment of the invention provided specifically comprises:
Step 101: after the related foundation that physical connection and user connect, the current physical connection that is in user mode is identified;
Wherein, said being designated:
For being connected with said user to create, said physical connection connects intermediary;
Said connection intermediary is carried out record.
In actual applications, can call the record of realizing in the context said connection intermediary by said connection intermediary is registered to.
Step 102: after this calls end, judge that this calls the middle physical connection of using and whether also has said sign, if then said physical connection is the physical connection that does not discharge.
After finding the physical connection that does not discharge, also comprise:
Step 103: remove said physical connection that does not discharge and related with between its corresponding user connects, deletion of physically connects the said sign that has.
After calling end; Through the inspection of said sign being judged whether the physical connection of using in the invoked procedure is released,, promptly also have this to call the middle connection intermediary of creating in the record if also have said sign; Then this connection intermediary corresponding physical connection of explanation also is not released; Related between said physical connection and user connect also is not disengaged, and through removing related between said physical connection and the said user's connection, deletes said connection intermediary and discharges said physical connection.
Preferably, after this calls end, also comprise:
Closing that the reception client is sent connects indication;
Connect indication and remove related between said physical connection and the said user's connection based on said closing;
Deletion of physically connects the said sign that has.
After calling end, do not close connection if application program is forgotten, close to connect through transmission so and indicate the notice connection pool to close connection, connection pool is indicated the work of closing connection according to said connection, and last release physical connects.
Referring to Fig. 2, the method that further embodiment of this invention provided specifically comprises:
Step 201: client is sent connection request to connection manager, and request connects.
In embodiments of the present invention, this connection request is a new call connected request; In other embodiments, this connection request also can be to be the connection request that a user who has existed connects a related physical connection.
Step 202: connection manager according to said connection request to physical connection of connection pool application.
Step 203: connection pool returns a physical connection according to said connection request.
When this connection request is a user who has existed when connecting the connection request of a related physical connection, in this connection request, carry this user connection information.
Said physical connection is the new physical connection that connection pool is created according to said connection request;
Perhaps, be the physical connection of an original free time in the connection pool.
Step 204: after connection manager receives the physical connection that connection pool returns, be that said physical connection distributes a user to connect.
When the connection request that receives is to be a user who has existed when connecting the connection request of a related physical connection, and said sharing out the work is specially:
Carry out related with the user's connection in receiving request the physical connection of obtaining.
Step 205: be connected establishment with the user according to said physical connection and connect intermediary.
Annexation between this connection intermediary comprises said physical connection and said user is connected; For example physical connection is No. 2 connections; The user corresponding with it is connected to No. 3 connections, and just comprise in the so said connection intermediary: No. 2 physical connection is connected continuous information with No. 3 users.
Step 206: said connection intermediary is registered to calls in the context.
Through being registered to, said connection intermediary calls the record of realizing in the context said connection intermediary in embodiments of the present invention.
Call context and be used for dynamic management and be registered in connection intermediary wherein, before calling beginning, the connection intermediary that is registered in is wherein preserved; After calling end, client indication connection manager is deleted from call context and is worked as the inferior corresponding intermediary that is connected of calling.
Step 207: user's connection is returned to client.
Step 208: use this user to connect and carry out data call.
Step 209: after calling end, client is sent to close to connection manager and is connected indication.
Step 210: connection manager remove this call in related between physical connection and the user's connection, this calls the connection intermediary of use to delete all.
In embodiments of the present invention, connect intermediary and be based upon in the physical connection, when being registered in the connection intermediary of calling in the context and being deleted, deletion simultaneously is based upon the connection intermediary in this physical connection.
Step 211: inspection calls to ask in the literary composition whether to also have this to call corresponding connection intermediary up and down, if having, and execution in step 210.
In the practical application, after the step 210, also comprise:
Connect related physical connection recurrence connection pool with having removed;
Perhaps, when connection pool is expired, directly the said physical connection that connects association of having removed is closed.
In fact; Connect intermediary and be equivalent to sign a physical connection; If promptly physical connection is being in invoked procedure, so its connection intermediary that comprises just be illustrated in this this call in this physical connection with which user be connected and combine to realize that this time call; Accordingly, after once calling end,, just will remove,, at this moment, just show that this physical connection also is not used, and is in upstate if this physical connection is returned connection pool to the sign of this physical connection through the connection intermediary deletion that physical connection is comprised.
Through the method that the embodiment of the invention provided, the connection intermediary between before calling beginning, setting up physical connection and its pairing user being connected, and it is registered to calls in the context; Just be equivalent to this moment record carried out in this user's connection and physical connection through calling context; After calling end, can normally close connection, to remove the user and connect the relation with physical connection, to make physical connection can get back to connection pool, thereby to realize multiplexing to physical connection if carry out according to step 109; But, if forgetting, application program promptly forgets execution in step 209 in embodiments of the present invention, pass through the inspection of step 210 so; The record that before utilization is called physical connection is connected with the user; Guaranteed that the user connects and physical connection between be associated in after time calling end and necessarily can remove, avoided connecting the appearance of revealing, and this registration and check and can realize automatically fully; Do not need the participation of application developer, solved the problem that connects leakage expeditiously.
In embodiments of the present invention, after the de-associated of said user's connection and physical connection, the user connects with physical connection just separate, and at this moment, physical connection can be put back to connection pool and carry out multiplexing; When connection pool is expired, can this physical connection be closed.
Do not need to carry out again data call if client is follow-up, can close this user so this moment and connect; Also need carry out data call when client is follow-up, can this user be connected reservation so.As long as promptly can be not influential again with the related of physical connection to physical connection because removed user's connection in embodiments of the present invention; Can not cause waste so keep user's connection this moment to physical connection; Can connect the user on the contrary and reuse; Referring to Fig. 3, when the user be connected once connect be retained and again the process called of this process data specifically comprise:
Step 301: client is sent connection request to connection manager, applies for connecting related physical connection for the user who self keeps.
Step 302: connection manager is that said user connects related physical connection according to said connection request.
In embodiments of the present invention, the physical connection of said connection manager free time of from connection pool, obtaining and said user's join dependency join;
Perhaps, a physical connection and the said user's join dependency created again according to said connection request of said connection manager joins.
Step 303: connection manager is connected with said user according to said physical connection creates connection intermediary.
Step 304: said connection intermediary is registered to calls in the context.
Step 305: client uses this user's connection to carry out data call.
Step 306: after calling end, client is sent to close to user side and is connected indication.
Step 307: remove this call between physical connection and the user connection related release all call the connection intermediary of use.
Step 308: inspection calls to ask in the literary composition whether to also have this to call corresponding connection intermediary up and down, if having, and execution in step 307.
In the method that the embodiment of the invention provided, because client is repeatedly carried out data call possibly, just this user's connection being kept, is to use in calling in the past so this user connects, but do not close.Because this user's connection is removed with the related of physical connection in calling before; Connect not generation connection leakage so keep this user; Opposite; Also realized reusing, when avoiding connecting leakage, also practiced thrift the establishment user and connected such process, further improved the efficient of data call what this user connected.
Embodiment is corresponding with method, and the embodiment of the invention also is provided for searching the device of the connection that does not discharge in the connection pool, referring to Fig. 4, comprising:
Identify unit 401 is used for after the related foundation that physical connection and user connect, the current physical connection that is in user mode being identified.
Wherein, said identify unit 401 specifically comprises:
Create subelement: be used to said physical connection and be connected establishment connection intermediary with said user.
The record subelement is used for the connection intermediary that said establishment subelement is created is carried out record.
Detecting unit 402 is used for after calling end, detects this physical connection of calling middle use and whether also has the sign that identify unit carries out said physical connection, if having, confirms that then the connection that is detected is connected to the physical connection that does not discharge.
Preferably, said device also comprises:
First releasing unit 403 is used for after said detection goes out undelivered physical connection, removes said physical connection that does not discharge and related with between its corresponding user connects, and deletion of physically connects the said sign that has.
Through the device that the embodiment of the invention provided, before data call receives through the connection intermediary that comprises the incidence relation between physical connection and the user connection is carried out record; Call and finish the back said record is detected, when time calling corresponding connections intermediary, just to remove its connection that comprises related when finding wherein to have, thereby release physical connects, and has effectively avoided the connection leakage.
Preferably, the described device of Fig. 4 also comprises:
Second releasing unit 404 is used for being put back to connection pool by the physical connection of the first releasing unit disassociation or closing.
Through second releasing unit physical connection that has been released is reused when connection pool is idle.
In other embodiments, device shown in Figure 4 also comprises:
Receiving element 405 is used to receive and calls closing of finishing that the back client sends and connect indication.
Said first releasing unit 403 also is used for connecting indication and removing said physical connection and related with between its corresponding user connects according to said the closing that said receiving element receives, and deletion of physically connects the said sign that has.
Like this, said device is the perfect function that connects of removing on the basis of avoiding revealing, and makes to call after the end can proper solution to remove the related of physical connection and user's connection; Close even client is forgotten, can forget the association of closing, avoid connecting the generation of leakage through the detection of record subelement is removed.
The present invention can describe in the general context of the computer executable instructions of being carried out by computer, for example program module.Usually, program module comprises the routine carrying out particular task or realize particular abstract, program, object, assembly, data structure or the like.Also can in DCE, put into practice the present invention, in these DCEs, by through communication network connected teleprocessing equipment execute the task.In DCE, program module can be arranged in this locality and the remote computer storage medium that comprises memory device.
The above only is a preferred implementation of the present invention; Should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; Can also make some improvement and retouching, these improvement and retouching also should be regarded as protection scope of the present invention.