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 achieving the above object, 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 described sign, if determine that then described physical connection is the physical connection that does not discharge.
Described method also comprises:
Remove described physical connection that does not discharge and related with between its corresponding user connects;
Deletion of physically connects the described sign that has.
After described this calls end, also comprise:
Closing that the reception client is sent connects indication;
Connect indication and remove related between described physical connection and the described user's connection according to described closing;
Deletion of physically connects the described sign that has.
Described physical connection and described user connect relatedly setting up in the following manner:
Creating one according to described physical connection is connected with the corresponding user of described physical connection;
Perhaps, connect for the related user who has existed of described physical connection.
Described physical connection is to connect the free time in the connection pool or is according to a newly-built physical connection of the connection request of client.
Described method also comprises:
Put into connection pool with having removed related described physical connection;
Perhaps, close the described related physical connection of having removed.
The described current physical connection that is in user mode is identified is specially:
For being connected with described user to create, described physical connection connects intermediary;
Described connection intermediary is carried out record;
Judge whether this physical connection of calling middle use has described sign and be specially:
Check whether also have this to call the middle connection intermediary that uses in the described record.
Described described connection intermediary is write down is specially:
Described connection intermediary recorded call in the context.
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 described physical connection, if having, then determines the physical connection that does not discharge that is connected to that is detected.
Described device also comprises:
First releasing unit is used for after described detecting unit detects undelivered physical connection, removes described physical connection that does not discharge and related with between its corresponding user connects, and deletion of physically connects the described 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;
Described first releasing unit also is used for connecting indication and removing described physical connection and related with between its corresponding user connects according to described the closing that described receiving element receives, and deletion of physically connects the described sign that has.
Said apparatus also comprises:
Second releasing unit is used for and will is put back to connection pool by the physical connection of the first releasing unit disassociation or close.
Described identify unit specifically comprises:
Create subelement, be used to described physical connection to be connected and create to connect intermediary with described user;
The record subelement is used for the connection intermediary that described establishment subelement is created is carried out record.
As seen, 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 described sign, if, determine that then described physical connection is the physical connection that does not discharge, by before calling physical connection is identified, call the back described sign inspection is look for the connection of closing, do not need artificial 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, equally needed connection closed.In the connection pool technology, introduce the user and connected this notion, application program and physical connection are kept apart, 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 by physical connection also can return to application program by 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 to connection pool, rather than is closed, and gets up with buffer memory and uses for visit next time, 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, may be many-to-one.
After the connection pool technology has been arranged, when needing in the enterprise application to communicate by letter with EIS, obtain physical connection from connection pool, rather than directly create a physical connection to EIS, because the connection of connection pool is pre-created, 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, therefore application program is finished after the operation with 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 finished 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, described being designated:
For being connected with described user to create, described physical connection connects intermediary;
Described connection intermediary is carried out record.
In actual applications, can call the record of realizing in the context described connection intermediary by described 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 described sign, if then described physical connection is the physical connection that does not discharge.
After finding the physical connection that does not discharge, also comprise:
Step 103: remove described physical connection that does not discharge and related with between its corresponding user connects, deletion of physically connects the described sign that has.
After calling end, by the inspection of described sign being judged whether the physical connection of using in the invoked procedure is released, if also have described sign, promptly also have this to call the middle connection intermediary of creating in the record, illustrate that then this connection intermediary corresponding physical connection also is not released, related between described physical connection and user connect also is not disengaged, and by removing related between described physical connection and the described user's connection, deletes described connection intermediary and discharges described physical connection.
Preferably, after this calls end, also comprise:
Closing that the reception client is sent connects indication;
Connect indication and remove related between described physical connection and the described user's connection according to described closing;
Deletion of physically connects the described sign that has.
After calling end, do not close connection if application program is forgotten, close to connect by transmission so and indicate the notice connection pool to close connection, connection pool is indicated the work of closing connection according to described connection, and last release physical connects.
Referring to Fig. 2, the method that further embodiment of this invention provided specifically comprises:
Step 201: client sends 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 the connection request that connects a related physical connection for a user who has existed.
Step 202: connection manager according to described connection request to physical connection of connection pool application.
Step 203: connection pool returns a physical connection according to described 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.
Described physical connection is the new physical connection that connection pool is created according to described 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 described physical connection distributes a user to connect.
When the connection request that receives is that described sharing out the work is specially when connecting the connection request of a related physical connection for a user who has existed:
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 described physical connection and connect intermediary.
Annexation between this connection intermediary comprises described physical connection and described 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 described connection intermediary: No. 2 physical connection is connected continuous information with No. 3 users.
Step 206: described connection intermediary is registered to calls in the context.
By being registered to, described connection intermediary calls the record of realizing in the context described connection intermediary in embodiments of the present invention.
Call context and be used for dynamic management and be registered in wherein connection intermediary, 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 sends to close to connection manager and connects indication.
Step 210: connection manager remove this call in related between physical connection and the user 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 when deleted, deletion simultaneously is based upon the connection intermediary in this physical connection.
Step 211: check to call to ask whether also have this to call corresponding connection intermediary in the literary composition up and down, if having, 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 described physical connection that connects association of having removed is closed.
In fact, connection intermediary is equivalent to the sign to a physical connection, if promptly physical connection is being in invoked procedure, so its connection intermediary that comprises just show call this this in this physical connection with which user be connected in conjunction with realizing 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 by the connection intermediary deletion that physical connection is comprised.
By 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 by calling context; After calling end, can normally close connection, to remove the user and connect 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 when time calling and finish back one and remove surely, avoided connecting the appearance of leakage, and this registration and inspection 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 described user connected related releasings with physical connection, user's connection and physical connection were just separate, and at this moment, physical connection can be put back to connection pool and carry out multiplexing; When connection pool is expired, this physical connection can 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 to carry out data call when client is follow-up, this user can 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 be reused, 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 sends connection request to connection manager, applies for connecting related physical connection for the user who self keeps.
Step 302: connection manager is that described user connects related physical connection according to described connection request.
In embodiments of the present invention, the physical connection of described connection manager free time of from connection pool, obtaining and described user's join dependency connection;
Perhaps, a physical connection and the described user's join dependency connection created again according to described connection request of described connection manager.
Step 303: connection manager is connected with described user according to described physical connection creates connection intermediary.
Step 304: described 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 sends to close to user side and connects indication.
Step 307: remove this call in related between physical connection and the user connection discharge all this call the connection intermediary of use.
Step 308: check to call to ask whether also have this to call corresponding connection intermediary in the literary composition up and down, if having, 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 that this user connects, when avoiding connecting leakage, also save the establishment user and connected such process, further improved the efficient of data call.
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, described identify unit 401 specifically comprises:
Create subelement: be used to described physical connection to be connected and create to connect intermediary with described user.
The record subelement is used for the connection intermediary that described 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 described physical connection, if having, determines that then the connection that is detected is connected to the physical connection that does not discharge.
Preferably, described device also comprises:
First releasing unit 403 is used for after described detecting unit detects undelivered physical connection, removes described physical connection that does not discharge and related with between its corresponding user connects, and deletion of physically connects the described sign that has.
By the device that the embodiment of the invention provided, before data call receives by the connection intermediary that comprises the incidence relation between physical connection and the user connection is carried out record; Call and finish the back described record is detected, just remove the connection association that it comprises when finding wherein to have when time calling corresponding connections intermediary, 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 and will is put back to connection pool by the physical connection of the first releasing unit disassociation or close.
By 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.
Described first releasing unit 403 also is used for connecting indication and removing described physical connection and related with between its corresponding user connects according to described the closing that described receiving element receives, and deletion of physically connects the described sign that has.
Like this, described 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 by 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 distributed computing environment (DCE), put into practice the present invention, in these distributed computing environment (DCE), by by communication network connected teleprocessing equipment execute the task.In distributed computing environment (DCE), program module can be arranged in the local and remote computer-readable 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 improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.