What happends if I dont close the connection

Hi,
I would like to know what happends if I dont close the connection after processing. we wont get any compile time & run time error if you dont close the connection. But why we used to close the connetion. Any specific reason for this. Please let me know.
Regards,
Satish

What happens if you don't close a connection? It depends on how many connections you open and how long your program keeps running.
Let's start with the case of a standalone program that runs for a little while then exits.
While the program is running, the operating system maintains a network connection to the database server for each open database connection; there are system limits on the number of open network connections, although this is usually a very high number. Also, every open connection to a database uses resources of the database; many databases have limits on the number of connections they can have open at once. Some database products or configurations (Oracle in "dedicated" mode) will also start a seperate process on the server for each open connection; too many open connections and these processes start swapping out to disk, too many more and the server runs out of memory.
When the program exits, the operating system will close any open network connections; the database server will also recognize that the network connections are closed. If the database supports transactions and the connection was in a transactional mode and there were uncommitted transactions, then the uncommitted transactions will be rolled back. Ultimately, all the database resources get released (assuming there are no bugs in the database program).
Thus, a program that runs for a few minutes, commits all its transactions and exits without closing connections doesn't do major harm; the operating systems of both the client and the database server clean up the network connection and the database itself cleans up the database connection. It's all designed this way because programs sometimes crash; you can't have a system/database that breaks when that occurs... However, this cleanup is not always absolutely immediate on program exit; it usually takes a short time, seconds to minutes, for everything to clean up. Therefore, if the same programs is run over and over real fast, it becomes possible to exhaust a resource, such as memory or network connections. For a quick little test program that's run once and that's it, no problem...
Now for a long running prgram, such as a web application that will run for days or months...
As I've alluded to above, each database connection uses system resources, both on the client machine and on the database server. When a connection is maintained open, those resources are tied up; there's always a limit on the total number of connections that can be supported, although with the right software, hardware and database configurations that limit can be a huge number, tens of thousands. For other systems, it might be a low number, hundreds or less. Whatever it is, the program could potentially reach that limit and cause something to fail. If it doesn't reach that limit (or cause another program to push past the limit) then there's no problem (other than a potential performance impact).
Now within a Java program, the JDBC standard requires that when an open database connection object is garbage collected, the connection is first closed. Assuming your driver conforms to the standard in this regard, and assuming no resource limit gets exceeded, then a long running program could open and abandon connections and let the garbage collector close and clean up. However, garbage collection is unpredictable, and connections are often sufficiently long lived that they get moved out of the "Eden" memory space and into the space of long-lived objects. These objects are only garbage collected when a "full" garbage collection takes place; a "partial" collection only examines the "Eden" space. Thus, depending on the applications load and memory usage and connection usage pattern and garbage collection configuration, an abandonded connection might not be garbage collected for hours or even days, greately increasing the chances that you run out of resources.
In other words, not closing your connections in a long running program is a really really bad idea.

Similar Messages

  • HT1212 I dissabled my ipod touch 4th generation. It says connect to itunes, and i did what it say to do but the "connect to itunes" screen never shows up...it just goes back to the "ipod is dissabled connect to itunes screen. What do i do?????

    I dissabled my ipod touch 4th generation. It says connect to itunes, and i did what it say to do but the "connect to itunes" screen never shows up...it just goes back to the "ipod is dissabled connect to itunes screen. What do i do?????

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        

  • Can I close the connection after sending immediately on the server?

    I have a C/S program. On the server side, the process as following:
    1. accept (blocking)
    2. //a connection is established
    using a new socket to receive request data from client
    3. business processing ... (maybe several seconds)
    4. send response data to client
    5. close socket immediately
    6. listening continuely again
    The server side is running on linux and writed by Java, and client is running on windows and writed by C++ Builder.
    My problem is:
    1. if the server is running on windows, everything is OK.
    2. if the server is running on linux (that is exprcted), the client can not receive the response data from server, the client program said the connection is unavailable when he read from socket blockingly.
    3. if I add some delay, e.g. 500ms, between sending response and close the connection, the client can receive response normally.
    why above?
    thanks for help.
    Jack

    Sorry, long time to go away.
    package test.server;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class EchoServer {
         private int port; // listened port
         private ServerSocket ssock; // the server's ip
         public EchoServer(String host, int port) {
              this.port = port;
              // Create a ServerSocket
              try {
                   ssock = new ServerSocket(port);
                   SocketAddress addr = new InetSocketAddress(host, port);
                   ssock.bind(addr);
              } catch (Exception ex) {
                   ex.printStackTrace();
              new HandleThread().start();
         public class HandleThread extends Thread {
              public int ntohl(byte[] bytes, int offset) {
                   int length1 = ((((int) bytes[offset + 0]) << 24) & 0xff000000);
                   int length2 = ((((int) bytes[offset + 1]) << 16) & 0x00ff0000);
                   int length3 = ((((int) bytes[offset + 2]) << 8) & 0x0000ff00);
                   int length4 = ((((int) bytes[offset + 3]) << 0) & 0x000000ff);
                   return length1 + length2 + length3 + length4;
              public void run() {
                   InputStream in = null;
                   OutputStream out = null;
                   try {
                        while (true) {
                             System.out.println("Start Listening...  [" + port + "]");
                             Socket clisock = ssock.accept();
                             //clisock.setSoLinger(true, 1);
                             System.out.println( "SOLinger:" + clisock.getSoLinger());
                             try {
                                  System.out.println("Accepted Client Socket...  [" + clisock + "]");
                                  in = clisock.getInputStream();
                                  out = clisock.getOutputStream();
                                  // receive four bytes length
                                  byte[] lenbuff = new byte[4];
                                  in.read(lenbuff, 0, 4);
                                  int len = ntohl(lenbuff, 0);
                                  byte[] buff = new byte[len];
                                  in.read(buff, 0, len);
                                  System.out.println("Received length&#65306;" + len + "  " + new String(buff));
                                  Thread.sleep(1000);
                                  out.write(lenbuff);
                                  out.write(buff);
                                  out.flush();
                                  //Thread.sleep(500);
                                  System.out.println("Send finished&#12290;");
                             } catch (Exception ex) {
                                  ex.printStackTrace();
                             } finally {
                                  if (in != null) {
                                       try {
                                            in.close();
                                       } catch (Exception ex) {
                                  if (out != null) {
                                       try {
                                            out.close();
                                       } catch (Exception ex) {
                                  if (clisock != null) {
                                       try {
                                            long time00 = System.currentTimeMillis();
                                            clisock.close();
                                            System.out.println( "close socket&#65306;[" + (System.currentTimeMillis() - time00) + "]");
                                       } catch (Exception ex) {
                   } catch (Exception ex) {
                        ex.printStackTrace();
         public static void main(String[] args) throws Exception {
              if( args.length == 2 ) {
                   new EchoServer(args[0], Integer.parseInt(args[1]));
              } else if( args.length == 2 ) {
                   new EchoServer("127.0.0.1", Integer.parseInt(args[0]));
              } else {
                   new EchoServer("127.0.0.1", 16000);
    }In my application, the package is following:
    length(4bytes) + data
    I have a simple WinSocket Client, send data to this server and receive the response,the sending is OK, Server can receive all messages.But when client is ready to receive data, the winsock call return WSAECONNRESET(10054).
    If I uncomment "Thread.sleep(500);", it means wait some time before close socket, the client can receive all response data.
    why?

  • What about if u dont remember the same apple id and pass which u bought the OS X LION how can i reinstall os x lion

    what about if u dont remember the same apple id and pass which u bought the OS X LION how can i reinstall os x lion

    Buy it again in your new Apple ID or remember the old one. That's about it.

  • HT2434 does anybody know what happens if I dont update the firmware of my macbook pro (does not have a guid partition scheme))

    does anybody know what happens if I dont update the firmware of my macbook pro (does not have a guid partition scheme)?

    Apple will hire a high school girls clique to follow you around, make fun of you & post disparaging comments on Facebook .

  • Using LabVIEW 6i w Win NT or 95/98 et al: how do you keep a TCP/IP open connection 'open'. The application closes the connection even though the refnum is still active (valid.)

    Actually, I open the TCP/IP connection and pass the connection ID through. Each command to/from (cycle) the UUT successfully executes. The refnum for the connection ID is then passed via a shift register in the while loop. i am using the type cast (4X) function to determine the validity of the connection and case statements. If the refnum is non-zero it assumes the connection is still open; if the result is zero, then the connection is closed and a new session opened in that case. What is happening is that the connection has closed and the refnum is still nonzero after the type cast function; su
    bsequent commands to the UUT then produce Error 1 for the TCP/IP function (there was no open connection, so there could be no write occurrence.) Obviously, this probably shouldn't be happening. If someone can give me some idea of what I am not doing, or am doing wrong, I sure would appreciate it. In the event that I open and close a connection for each command to(from)(cycle) the UUT everything works. It is extremely slow. The connection should remain open according to all the pointers in the Help and TCP/IP function descriptions. Some of this application is proprietary, so not sure how much of an example I could use to illustrate from a VI, but if this doesn't get any where, I will see what i can do to better illustrate the problem...Thanks. T.Raper

    I believe this is a related question. I am developing a LV application the uses TCP/IP to control up to 8 devices-under-test (DUT) at one time. They start and finish testing at arbitrary times relative to each other, and the IP addresses are not known until the DUT arrives. I have some question on what is the best way to manage the TCP/IP handles.
    Presently, I have 8 Global IP addresses (one per testing site) that are updated as DUTs arrive and depart, and then whenever I need to communicate with a DUT I use TCP-Open, Write/Read, and TCP-Close. I do this Open/Write/Close each time there is a message to be sent to a DUT. This is basically working, but I notice that the OS (Windows XP or 2000) is running through local TCP/IP ports at a ferocious rate due to the TIME_WAIT behavior of Closed TCP/IP ports (It takes many minutes for a local port to become available again after being closed). If I am not careful, I can quickly exhaust the pool of OS ports by using tight polling loops or other very quick DUT accesses. I have tried not to do that in order to avoid running out of handles, but it is still very wasteful of ports.
    While it is working, I feel so dirty burning through these handles like this since they appear to be a precious resource. I really cannot easily merge multiple Read/Writes into a single Open/Close since there are dozens of otherwise unrelated tests that communicate with the DUT as a part of their functionality. The tests are even in different subVI's that are accessed via a vi-server, and only one is loaded at a time.  
    I thought that a cute idea would be to cache the handles in Globals, and wrap the Open to use the cache if valid, but reading this thread is making me think it is a lot of effort -- I believe I would need to keep a VI running as a "IP Connection Server" at all times and use some form of messaging to get it to Open/Close TCP connections as needed. Since the DUTs arrive at aribitrary times, and with random IP addresses, I cannot establish all the TCP handles ahead of time -- they would need to be created dynamically. It is much more difficult than simply keeping the Connection IDs in global variables -- the VI that Opened them must not be allowed to terminate.
    So... I am curious...... is it really that bad to Open/Close as frequently as I am doing it? Does it make me a bad person? I understand it is inefficient use of time, but the simplicity it brings to the structure seems huge, and the DUT is very slow anyway. And if it is bad, are they any more recent thoughts on alternatives? Do VISA handles behave the same way as TCP handles (ie. auto-close themselves upon exit of the VI that Opened them) ?
    Message Edited by Mike Seibel on 11-28-2005 07:55 PM
    Message Edited by Mike Seibel on 11-28-2005 08:00 PM
    Message Edited by Mike Seibel on 11-28-2005 08:01 PM

  • PO issue :What should we do to close the PO or change item quantity?

    Hi Everyone,
    I am new to MM.I got an issue saying that there is some mismatch with quantity in the particular PO. User wants to cancel/close the PO system but it is not allowing to do so. To change the quantity is also  good, but while trying to change item quantity system is giving the following error message.
    Quantity 1000 is smaller than quantity issued 2000.
    To close the PO or change item quantity what should I need to do?
    A help will be highly appreciated
    Regards,
    sharon.

    Hi,
    It is of the standard functionality of SAP to verify the GR and IR against PO quantity when you try to close your related PO line item.  It ensures data consistency for your PO and PO history.  What you should do is very much subject to the status of your PO history (i.e. how many you have already GRed and/or IRed).  Check it again in your PO history tab of the PO item details level prior to making any further action on how your PO line item quantity shall be adjusted.  A particular example is if GR was done for the quantity of 2,000, you can't simply adjust your PO quantity into 1,000 as it goes against the logic whereby the GR quantity (and/or IR quantity) must be no larger than PO quantity.
    Cheers,
    HT

  • Do v need to Close the Connection

    Hi plz tel me
    1. Do v need to Close the Database Connection ?
    2. which is better to use Statement or ResultSet Interface ?
    Thanx in Advance

    Hi plz tel me
    1. Do v need to Close the Database Connection ?
    2. which is better to use Statement or ResultSet
    Interface ?
    Thanx in AdvanceHi sumit.manhas,
    For your info, refer these links....
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.htmlpublic interface Statement
    The object used for executing a static SQL statement and returning the results it produces.
    By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists.
    http://java.sun.com/j2se/1.4.2/docs/api/java/sql/ResultSet.htmlpublic interface ResultSet
    A table of data representing a database result set, which is usually generated by executing a statement that queries the database.
    A ResultSet object maintains a cursor pointing to its current row of data. Initially the cursor is positioned before the first row. The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set.
    Regards,
    JavaDriver

  • What does this mean?? "The connection to the host was unexpectedly lost."

    i get this 95% of the time i try to login:
    The connection to the host was unexpectedly lost.
    it then closes
    i go thru AIM
    _*someone please help*_
    Message was edited by: migueliguel
    Message was edited by: migueliguel

    Hi
    Try logging on to AIM on port 443 rather than port 5190.
    Go to IChat in the menu bar > Preferences > Accounts.
    Log out of AIM and then use the Server Settings tab
    Set the port to 443.
    Log back in again.
    Tony

  • Blackberry 8800 closes the connection with the desktop manager

    i have blackberry 8800... when i try to connect with the desktop manager 5.0 it connects flawlessly but after some seconds a message appears that your device has lost the connection with the desktop manager but even then the usb sign stil being showed infront of the battery indicatior... after some seconds of losing the connection, it connects again and disconnects again and this is goes on ....
    i need help please
    regards

    please help me . is theres any solution to it. done battery replacment reset. but nothing happens

  • Hello..I don't like to admit I am a dumby ,but I am. I've had this mac book (white 13) for yrs now and have no Idea what it is or what I am doing(except the power botton) Will someone please help me. Idon't know what I have,I dont know the software or wha

    I need a teacher. I have a mac book 13 white. I have all kinds of files/stuff that I have been downloading. I dont know how to update a app, or how to tell what I have as far as memory/software/ version(of what?) I know that I can not sync my 3gs 32g iphone. I know that most all my applications will not work on this version of ??? . I spend hours just trying to get on line,most the time I give up. I've had this thing for years ,I click chx for updates , most everytime it says "no internet".....I do know for how bad I feel inside, all the hours that I have spent on this thing with no closure that I would rather smash it into tiny pieces then sell it. I do not have money anymore..I am very smart at all sorts of differant things in life .I am not smart at understanding to basic function or opperations of computers , I am missing something, I am close ,but just can not wrap my mind around it.
      I am reaching out for help, I have nothing to offer , Your reward would come from the Gods , And knowing that you helped another human being. Trust me if feels good to help teach others how to fish for themselves.
      Thank you for taking the time.
    Jeff 
    < Edited by Host >

    Clntxwhtby wrote:
    Hay thank you for your time . I do that every time I know I am online. It says that I am up to date . I have found that I have 10.4.11 version, and that my boot version is 10.6.2, and that my kernel version is 8.11.1.
    I have a hard drive icon on my desktop that says 10.6.2....
    I use to have iphoto, it doesnt open anymore, it says there is 1.2gigs on that disk.There are many things on here that are the same way. Where do I start?
    It's always good to go with one thing at a time and stay focused on that. Let's start with the OS you're running. Click on the Apple menu > About This Mac. What does it say under Mac OS X version ?

  • Everytime I set up my macbook as a wifi hotspot it closes the connection on my macbook.  Why does that happen?

    Everytime I set up my computer as a wifi hotspot it closes my computer's internet connection.  Why is that happening?  And What can I do?

    With a Thunderbolt to Ethernet adapter in use, your MacBook Pro's Network Preferences should be similar to this:
    "Status" should be "Connected", a valid IP address should appear, and you should be able to load web pages. Make that work first.
    Then make your MacBook Pro's Sharing preferences resemble this:
    Essentially: "Share your connection" and "To computers using" should be as shown above.
    The MBP's Wi-Fi icon will be as shown below:
    To other client devices, the network they join should be the name you designated. It will appear in the same manner as any other wireless network.
    What are you seeing that's different than the above?

  • What happended to "Save As" in the SQL Worksheet?

    I am using 14.22 in Windows XP. In the previous version 13.43 I used to:
    1) Open a new SQL Worksheet.
    2) Type in statements.
    3) Press Ctrl-S to save the contents of the SQL Worksheet panel to a new file, an "Open File" dialog appeared.
    4) Enter file name for new SQL script file.
    Now when I press Ctrl-S I do not get the "Open File" dialog. The Ctrl-S saves the SQL Worksheet contents to a temp file in my user/.sqldeveloper/tmp directory. I have to copy the contents of the SQL Worksheet panel into a text editor and save it to a SQL file. Or I copy the SQL file in my temporary directory to the new file I want.
    I saw in another thread that the SQL Worksheet contents is not being saved to a temporary file to help prevent loss of contents if there were a machine outage. This change may have caused this problem.
    I use the "Save As" functionality in the SQL Worksheet a lot. That was how I create SQL files.
    How do I create a SQL script in SQL Developer now?
    Mike

    It got dropped by accident but it will be back in for EA7 that we expect to release any day now (just writing the release notes for it now). We have the Save As back in the menu and a right-click Save File from the Worksheet to save your work.
    -- Sharon

  • What happended to DAB Radio on the N8?

    Just dug out my headset to give it another go but can't find the app in Nokia store, where's it gone???
    Does it work anyway? I didn't have much luck last time I tried.
    Nokia N8 on Belle

    secarica wrote:
    Was http://store.ovi.com/content/78485 but it appears it's no longer available. By looking into www.archive.org it seems it has disappeared sometime in 2012.
    Cristi
    Is this thing on?
    I just installed the DAB radio app as a software update on a new (to me) N8 a couple of days back.

  • What if we do not close the app

    I would like to know the consequences of not closing an app.

    I'm going to step out on a limb and assume your question is the old misunderstanding of an Apps state (multitasking) when you run another App. If so here is a great article in MacWorld that will answer all your questions.
    http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html

Maybe you are looking for