Keep JDBC connection alive

Hi,
I am running into problem with JDBC connection outside of the firewall. The firewall disconnect idle connection after 15min. Is there a way to keep JDBC alive for
as long as the application is running?
Thanks,

Notwithstanding connection pools generally managed by an application server, I would not advocate keeping a connection open beyond the immediate need for it. Certainly there is a performance cost to open a connection and that must be weighed against the potential for orphaned resources by leaving a connection in a trapped state. Personally I have never found an overriding NEED to keep a connection open beyond the method where the connection was first opened.
Using a connection pool makes the cost even less to open and release connections on an as needed basis.
Just my 2 krupplenicks worth, your mileage may of course vary.
PS.

Similar Messages

  • Please Help - To keep LDAP connection alive

    Hi,
    I have used the below function to communicate with LDAP which I have taken and modified from one of the posts in this forum.
    My issue is, each time the function opens a connection, search and closing the connection and its seriously affects the performance.
    I hope we can resolve this by keeping the connection alive. As I am new to this concept, I am not sure how to do this.
    It would be great, if some one help me to keep the connection alive for the below function. Thanks in advance.
    create or replace FUNCTION <name> (loginname VARCHAR2)
    RETURN NUMBER
    IS
    -- Adjust as necessary.
    l_ldap_host VARCHAR2(256) := '';
    l_ldap_port VARCHAR2(256) := '';
    l_ldap_user VARCHAR2(256) := '';
    l_ldap_passwd VARCHAR2(256) := '';
    l_ldap_base VARCHAR2(256) := '';
    l_retval PLS_INTEGER;
    l_session DBMS_LDAP.session;
    l_attrs DBMS_LDAP.string_collection;
    l_message DBMS_LDAP.message;
    l_filter varchar2(35):='xxxx='|| loginname;
    l_count NUMBER:=0;
    BEGIN
    -- Choose to raise exceptions.
    DBMS_LDAP.USE_EXCEPTION := TRUE;
    -- Connect to the LDAP server.
    l_session := DBMS_LDAP.init(hostname => l_ldap_host,portnum => l_ldap_port);
    l_retval := DBMS_LDAP.simple_bind_s(ld => l_session,dn => l_ldap_user,passwd => l_ldap_passwd);
    -- Get attribute
    l_attrs(1) := 'xxxx';
    l_retval := DBMS_LDAP.search_s(ld => l_session, base => l_ldap_base, scope => DBMS_LDAP.SCOPE_SUBTREE, filter => l_filter, attrs => l_attrs, attronly => 0, res => l_message);
    l_count:=DBMS_LDAP.count_entries(ld => l_session, msg => l_message);
    -- Disconnect from the LDAP server
    l_retval := DBMS_LDAP.unbind_s(ld => l_session);
    return l_count;
    EXCEPTION
    WHEN OTHERS THEN
    dbms_output.put_line('Error :'||SQLERRM);
    return 0;
    END <fun name>;
    Thanks,
    Praveen
    Edited by: 920577 on Mar 13, 2012 9:40 AM
    Edited by: 920577 on Mar 13, 2012 9:41 AM

    The basic template looks as follows:
    SQL> create or replace package Foo as
      2 
      3  procedure LdapLogoff;
      4  function GetData( empName varchar2 )  return number;
      5 
      6  end;
      7  /
    Package created.
    SQL>
    SQL> create or replace package body Foo as
      2 
      3  isLoggedOn boolean;
      4 
      5  procedure LdapLogon is
      6  begin
      7          DBMS_OUTPUT.put_line( '..running logon()' );
      8          isLoggedOn := true;
      9  end;
    10 
    11  procedure LdapLogoff is
    12  begin
    13          DBMS_OUTPUT.put_line( '..running logoff()' );
    14          isLoggedOn := false;
    15  end;
    16 
    17  function GetData( empName varchar2 ) return number is
    18  begin
    19          if not isLoggedOn then
    20                  LdapLogon();
    21          end if;
    22         
    23          DBMS_OUTPUT.put_line( '..running GetData() for '||empName );
    24          return(
    25                  round(DBMS_RANDOM.Value(1,100))
    26          );
    27  end;
    28 
    29 
    30  --// main()
    31  begin
    32          DBMS_OUTPUT.put_line( 'Package Foo loaded into memory' );
    33          isLoggedOn := false;
    34  end;
    35  /
    Package body created.
    SQL>
    SQL>
    SQL> select empno, ename, Foo.GetData(ename) as ID from emp order by empno;
         EMPNO ENAME              ID
          7369 SMITH              23
          7499 ALLEN              47
          7521 WARD               88
          7566 JONES              71
          7654 MARTIN             91
          7698 BLAKE              28
          7782 CLARK              92
          7788 SCOTT              91
          7839 KING               48
          7844 TURNER             89
          7876 ADAMS              64
          7900 JAMES              16
          7902 FORD               18
          7934 MILLER             35
    14 rows selected.
    Package Foo loaded into memory
    ..running logon()
    ..running GetData() for SMITH
    ..running GetData() for ALLEN
    ..running GetData() for WARD
    ..running GetData() for JONES
    ..running GetData() for MARTIN
    ..running GetData() for BLAKE
    ..running GetData() for CLARK
    ..running GetData() for SCOTT
    ..running GetData() for KING
    ..running GetData() for TURNER
    ..running GetData() for ADAMS
    ..running GetData() for JAMES
    ..running GetData() for FORD
    ..running GetData() for MILLER
    SQL>
    SQL> select empno, ename, Foo.GetData(ename) as ID from emp where rownum = 1;
         EMPNO ENAME              ID
          7369 SMITH               9
    ..running GetData() for SMITH
    SQL>
    // call Foo.Logoff manually when done, or leave it to
    // Oracle to close and release resources when the
    // session terminates

  • ADK - Keeping EIS Connections Alive

    Hi,
              I am using the ADK that comes with WL 8.1 SP3. The challenge I am facing is to keep my connections alive while there is no activity (at the TCP/IP socket level) between the app server and the EIS.
              The EIS closes any sockets after 30 minutes of inactivity causing the connections to go into CLOSE_WAIT state.
              Is there any method I can use within the connector to keep pinging the server and make sure these connections have TCP/IP traffic?
              Has anyone used the <test-frequency-seconds> weblogic-ra.xml? What is its purpose? pinging?
              Appreciate your insight..

    Hi
              I have a requirement, which is some what similar to what is mentioned above.
              I too have to ping the interface at regular intervals to keep the connection alive. I also assumed that, we can use the test-frequency-seconds attribute. But for that to work, we have to implement the interface, http://java.sun.com/j2ee/1.4/docs/api/javax/resource/spi/ValidatingManagedConnectionFactory.html, which is there only from weblogic 9.
              But since our client is using weblogic 8.1, we are tied to that version.
              Can anyone please assist in solving this.

  • Keep wifi connection alive

    Hi. I've noticed that after moving from opensuse to arch, my wifi connection dies on me after inactivity. I've tried this workaround:
    * Add a crontab to ping a website every 15 minutes. I'm using this command:
    * ping -c 4 www.google.com
    However, the connection still dies. Is there a better way to keep my connection alive? Perhaps if I increase the number of packets?

    As per this ubuntu forum post, I found something that might do the trick
    http://ubuntuforums.org/showthread.php?t=420959
    Adapted to arch, this may work:
    #!/bin/sh
    HOST=www.google.com
    ping -c 1 -W 10 $HOST &>/dev/null
    if [ $? -eq 0 ]; then
    #ping is ok
    exit
    else
    #first try
    ifconfig wlan0 down
    sleep 3
    ifconfig wlan0 up
    sleep 10
    ping -c 1 -W 10 $HOST &>/dev/null
    if [ $? -eq 0 ]; then
    exit
    else
    #second try
    /etc/rc.d/wlan restart
    /etc/rc.d/network restart
    iwconfig wlan0 essid NOAH_S_ARK
    sleep 10
    ping -c 1 -W 10 $HOST &>/dev/null
    fi
    fi
    The corresponding root crontab entry to run it every 20 minutes is
    */20 * * * * <nameofscript>
    Gonna try when I get home.

  • How to keep the connection alive?

    Hello! Happy new year!
    I have to write an HTTP server that comunicates with many clients in the same time,but keeps the connection with a client open if there the corresponding header is Keep-Alive. I have used threads,and I've tested my program in the following way: I've requested the one page of the site and then I've followed a link from that page. I expected that the broowser and the server talk to the same thread every time,but it seems that they don't. The code I've written is:
    //HTTPServer class
    ServerSocket serverSocket = null;
            boolean listening = true;
            try {
                serverSocket = new ServerSocket(80);
            } catch (IOException e) {
                System.err.println("Could not listen on port: 80.");
                System.exit(-1);
            while (listening)
                  new HTTPMultiServerThread(serverSocket.accept()).start();
    //HTTPMultiServerThread
    public void run() {
         //     System.out.println(socket.toString());
              try {
    while(!serverSocket.isClosed())){
                  DataOutputStream out = new DataOutputStream(socket.getOutputStream());
                  DataInputStream in = new DataInputStream( socket.getInputStream());
                  int nrBytes = in.available();
                  if(nrBytes > 0){
                       byte[] bytes = new byte[nrBytes];
                       in.read(bytes);
                       System.out.println("Procesez mesajul:" + nrBytes + new String(bytes));
                       HTTPMessage processedMess = new HTTPMessage(bytes).processMessage();
                       System.out.println("Inchid conexiunea.");
                        log("log.txt", new HTTPMessage(bytes).getStatusLine() + " " + new Data().getCurrentTime());
                   //send the message   
    out.write(processedMess.getBytes(),0,processedMess.getBytes().length);
                       /* inchid conexiunea
                  else{
                       String ret = new String("HTTP/1.1 500 Internal Server Error\n");
                        ret += "Host: cristi\n";
                      ret += "Date: " + new Data().getCurrentTime()+"\r\n";
                      ret += "\r\n";
                      ret += "<html><body><p>HTTP/1.1  500 Internal Serve Error</p> </body><html>\r\n";
                      out.write(ret.getBytes());
                  out.close();
                  in.close();
                       if(new HTTPMessage(bytes).getHeaderValue("Connection").equals("Close"))
                  socket.close();
         }//end while
              } catch (IOException e) {
                  e.printStackTrace();
        }I would also like to know how many clients are waiting to be served,in order to develop statistics about the server response time. 10X

    hi
    same to u .
    i think what i get from ur code that ....
    use some vector at the server side and whenever any client is connected (offcourse first time or not (depend on u !!)) create an object corresponding(generally created by server for every client) ..
    save this in the vector .. and pass it the size of vector to the client with the response .
    may this help u .
    regards
    akash
    Indiagames Ltd
    [email protected]
    India

  • Oracle keeping JDBC connections ...

    All
    has anyone come got any ideas on this:
    WLS6.0 sp2 on Win2k
    Oracle v8
    JDBC connection pool configured with 10 min connections / 50 max conns (in
    increments of 5). Shrinking is active, and is set to run every 15mins.
    What were seeing is that Oracle doesnt let go of any of the JDBC
    connections. It literally keeps them for days on end, until we have to
    manually kill them because theyre causing other DB problems.
    any ideas ?
    tks
    will

    Hello, I am using ALUI G6 (former Plumtree) and I am experiencing the same problem.
    JDBC connections are not released and we reach the connection max number easily.
    Please, can somebody help us ?
    Thanks for your help,
    Kind regards

  • Keep database connection alive

    I'm developing a windows desktop (standalone) application which runs as an endless loop.
    Once the application started, a database connection is created (java.sql.Connection) and from now on used to read data from the database.
    Connection is created like this:
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    Connection con = DriverManager.getConnection(connectionUrl);
    Does the connection will be kept alive forever?
    If NOT, what to change in my program?
    Edited by: user10511764 on Jun 26, 2011 4:47 AM

    If you are going to be continually using your JDBC connection, then you don't
    really need to go to the added complexity of using pooling. Just use the connection
    indefinitely, and unless there is some DBMS or firewall configured lifetime limit,
    barring error, the connection should be fine indefinitely. If you get an occasional
    failure, just make a new connection. A pool won't do any better, and if/when it
    makes a new connection for you, you will have to re-obtain all your statements
    etc, just as if you remade your own connection...

  • Freeware utilities for keeping network connection alive?

    Hi, I am wondering if anyone has recommendations for a freeware utility that can keep the network connection alive on my 2010 mac mini.
    Already have sleep, screen saver, and password lock turned off.  Also using static IP.
    When it sits for a while I can no longer ping it from my PC workstation or use iTunes, VNC etc from my phone.
    When I open up the mac, which I am using as HTPC, it will connect right away to Google etc using Safari yet it has dropped the share connection to my PC.
    Thanks!  Sean

    Thanks for the report!

  • Mail.app keeping IMAP connections alive and active

    Hi all,
    I was having some issues with the MySQL databases on my website, so I gave my hosting provider a call.
    It seems that Mail.app is opening up an IMAP process for each of my 24 e-mail accounds, and keeping it alive for as long as Mail is running. According to the representative I spoke with, e-mail clients, even with IMAP should start a process, synchronize the mail, and close the process, and all of this should happen in around 0.2 seconds.
    The problem is that there is a cap of 20 processes on my hosting server, so Mail's behavior is basically causing lots of problems - as long as mail is open and all of my accounts are enabled, my website can't access my MySQL databases.
    Does anyone know of a solution to this problem? I used to have "Automatically synchronize mailboxes checked" and tried unchecking this for troubleshooting purposes, but the same thing still happens.
    Any ideas or suggestions will be very appreciated.
    Thanks!

    From what I've read, imap is designed to create a persistent connection, and keep it open until you quit the program.
    But there's another problem which might be getting in your way: mail.app does indeed create persistent connections, but then rather than re-using them, it seems to open another new persistent connection each time it checks the mail. So the processes never close, and they start to pile up as new ones are added.
    What's more, mail opens multiple connections per account. Looks like it opens 4 connections to check each separate account, and those all get left open until you quit the program.
    The reason they do this is, so they say, "performance". More connections = faster mail. But it's a real headache when it doesn't close old processes before opening new ones.
    Also an option to limit the number of connections made per account would be welcome.
    Thunderbird does exactly the same thing, by the way.

  • How to keep NetStream.Connect alive even when noone is connected?

    is there any timeout set for NetStream.Connect? I am having an issue when one streamer goes to 2way channel and waits for another party to join but after about 1 minute (if noone is receiving that streamer signal) the NetStream.Connect.Close event is fired up. I want to be able to wait little bit longer.
    Any help much appreciated.

    Dear Alll,
    Please help.

  • Inactive Oracle JDBC connections

    I wonder if someone from the JDBC development group can answer this question.
    From talking to the JDBC support person ,
    I could get the following bit of information
    which may or may not be completely correct.
    He mentioned that if a connection is idle
    for a long period of time ( By idle, I mean
    no transaction is active), the resources associated with the connection could be recycled by the JDBC driver. It is the
    application's responsibility to keep pinging the connection if the application desires to keep the connection alive.
    Is the above correct? There is no mention of
    such behaviour in the Oracle JDBC documentation.
    null

    No, this is not true. We don't recycle
    any resources if the connection is active
    (i.e. it's not closed).

  • How to keep connection alive?

    I wondering if there is any way to keep connection alive during some period of inactivity.
    I have the SQL Developer 1.2.1 (it is not easy to update as I have no admin privileges on work computer) under Windows XP, connecting to Oracle9i Enterprise Edition Release 9.2.0.6.0.
    The inconvenience is that the connection become dropped after some inactivity time.
    What I have to do is to disconnect and connect again. But if I run any query in dropped connection condition it would take long time before it come back with a message that there is no connection.
    I could not find any kind of 'stay connected' option. (Like it is in some other application with time set possibility to send a some request to a server just to stay connected (for exm: PuTTY))
    To do it by myself it would be done by having some continuously looping script, that would run some simple select (say, sysdate) periodically, but I do not know if it possible to do it from SQL Developer.
    If it done in PL-SQL, it will be processed in Oracle, not in SQL Developer; so, it is not useful.
    Does anybody have or know any suggestion or advice to keep connection stay active?
    Appreciate any help!
    Alex
    Message was edited by:
    alex5161

    The trouble is shared connections. While the dbms_lock.sleep is sleeping, the connection will be frozen.
    Having said that, the real solution is to fix how sqldeveloper handles lost connections. Session timeouts are usually there for a reason and client software needs to learn to live with it.

  • Keeping a connection cache alive between program executions (pool)?

    Hey all,
    I am using the Oracle Connection Cache to maintain a connection pool. I have a java application that simply retrieves a document from an Oracle 8.1.7 database during each execution. In order to avoid the overhead of establishing a connection every time this simpe application executes, I'd like to use a connection pool/cache. However, I am not sure how to keep this connection cache "alive" between executions of my program. Basically, I would like to keep a connection cache to the database for an infinite amount of time. Does anyone know how I would do that? This way, my Java application will never have to make a new physical connection to the database in order to retrieve a document. I would really appeciate any help as I have spent a lot of time searching/reading/testing.
    Thanks,
    Marcus

    An application server would be the easiest solution, at least from a high level. Application servers exist to provide services like connection pooling to Java applications-- they're very good at it.
    If we're talking about code that's already been designed and written and whose deployment would be adversely affected by going to an application server, converting the process to a deamon would probably be the easiest approach.
    If you were to go down this road, you'd first have to identify what precisely should trigger the application to run. Perhaps it's a GUI, perhaps it's the creation of a file in a certain directory, etc. Then, you'd need to have a thread that monitored that (or registered as a listner for the appropriate event if we're talking about a GUI) and "woke up" the application.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com

  • How to keep the internet connection alive?

    Hi, I am a new Macbook user and everytime my computer goes to screen saver or sleep mode it keeps losing the internet connection. Is this normal? Is anyway to keep the internet alive even is the computer goes to "sleep mode"?
    I mean, it is quite a pain to keep signing in at messenger everytime I wake up my computer or come back from screen saver
    Thank you

    I do not know of a way. When your computer goes into sleep mode, it basically shuts itself down and stores everything in memory. Nothing is moving or working because the whole point of sleep mode is to conserve the battery. If it is really bothering you, go into System Preferences and change the amount of time it takes for the computer to go to sleep.

  • Keep connection alive?

    Hi.
    I am trying to make a http connection to a site and reuse the connection to fetch several pages.
    Here is the code I copied from java.sun.com and modified
    import java.net.*;
    import java.io.*;
    public class URLConnectionReader {
        public static void main(String[] args) throws Exception {
            URL url= new URL("http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html");
            URLConnection conn = url.openConnection();
            BufferedReader in = new BufferedReader(
                                    new InputStreamReader(
                                    conn.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
            in.close();
                url  = new URL("http://java.sun.com/docs/books/tutorial/networking/sockets/index.html");
            conn = url.openConnection();
            in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
            in.close();
    }When I call url.openConnection() again, a new connection is open and assigned to conn.
    However, I don't want to have a new connection since the program will be slow if there are a lot of threads are running at the same time....also, there is some overhead time to create a new connection...
    Is there anyway to reuse the existing connection?
    Thanks.

    In 1.4.x (I didn't check the other versions), there is a system property called http.keepAlive (http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html). By default this property is set to true. This will keep the connection to the server open for a limited time (I think it is in the order of 5 seconds). All this is done underwater in the networking libraries,
    You could also checkout http://jakarta.apache.org/commons/httpclient/. It supports keepalive.
    Cheers,
    --Arnout                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Maybe you are looking for