Is it okay to keep an MBeanServerConnection alive

I'm writing a monitoring application which constantly monitors the performance of a certain application. I get the performance numbers by invoking some methods through JMX every 5 min. Should I open up a MBeanServerConnection and use that connection object all the time for invoking the method, without ever closing it? Or should I reconnect every 5 minutes? What is the best practice in this case?
Thanks a lot in advance.

Hi Joanne,
Yes, this is perfectly OK, and I would even recommend to do so.
Opening a new connection would be more costly - especially if it's secured.
The JMX connector may transparently close and reopen the connection behind
the scene if it is not being used.
If you have only one connection (or only a few connections) I would suggest that
you open your connection when you start your monitoring
application, and close it only at the end when you stop the application and no
longer need it.
If however you are monitoring a large number of agents from the same client
JVM, you may want to reconsider your decision - since having a large number
of connections opened and alive in parallel in that client JVM may lead to
scalability issues on the client side.
Hope this helps.
-- daniel
JMX, SNMP, Java, etc...
http://blogs.sun.com/jmxetc

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.

  • Possible to attach an Interactive pdf to DPS ? ( & Keep the interactivity alive )

    Hi,
    Is it possible to open an interactive pdf from an DPS app and keep the interactive alive
    ( buttons /textboxses /submit / send to email ) ?
    I know how to make an zip-folder and link to the document form a button ( HTMLResources/filename.pdf )
    But the pdf is flatten , and the document is useless for my purpose.
    It would be great if this worked, and Adobe DPS could be even more handy than it is to day
    I know it's also possible to import html to indesign, and I have tried to make a form in Dreamwaver.
    The form looks nice on the Ipad & the buttons/ text fields works. But when I press submit ( mailto url )  the email opens.. But no data follows.
    ( Might be something wrong with the form of course )
    If I could link to Adobe Reader ( where the document already exist ) from the DPS-app.. that could be an solution/ and the interactivity works in Reader..
    But I haven't found any way to do that.
    My wish for the DPS of the future is that it would be more like MUSE. More options/ menus and no coding
    If someone have any good ideas on this issue, please let me know.

    Hi, after my first post in this issue I have solved the problem my self.
    The answer is to use Dreamweaver.
    1. Create an form with all the information you need in Dreamweaver. Be aware of the pixel value of the form, should not be larger than the Ipad
    Import the HTML into Indesign (Object /import HTML )
    If the form is larger than the Ipad - You can resize the imported html "frame" and use scale to fit in the web content menu.
    But in this way you don't have 100 % control of what your doing.
    After you imported the code in Indesign, and used the settings you like in web Content ( Folio Overlays ) Upload the DPS article as usual.
    2. Another way is to create an HTML article, where you import a folder with all files the form consist of ( Pictures, CSS and the HTML form  )
    A lot more you can do in this way like dropdown menues, fading images ++ . But is a bit more complicated workflow. So go for nr. 1

  • Okay, I keep getting this prompt That says "To view this context, you need to install the Java Runtime Environment...I believe I have clicked on the More Info link days ago..I believe this is malware..what do I do to get rid of this annoying pop-up?

    Okay, I keep getting this prompt That says "To view this context, you need to install the Java Runtime Environment...I believe I have clicked on the More Info link days ago..I believe this is malware..what do I do to get rid of this annoying pop-up? https://www.dropbox.com/s/gtm3khm6ngo0d26/Screenshot%202014-12-10%2019.56.56.png ?dl=0

    jackallday wrote:
    Kappy, got a page when I clicked saying it can't find the page and it looks like THIS https://www.dropbox.com/s/ldjyssatbmy53u0/Screenshot%202014-12-10%2021.28.24.png ?dl=0
    Try http://support.apple.com/kb/DL1572
    27" i7 iMac (Mid 2011) refurb, OS X Yo (10.10.1), Mavs, ML & SL, G4 450 MP w/10.5 & 9.2.2

  • 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.

  • Keep my Stopwatch alive! Searching for a Stopwatch App!

    Does anyone know of a free or paid Stopwatch app that keeps the display alive? Or an option to allow for this?
    I need to see the stopwatch and the display keeps going off.
    Thank you for your help!

    I found one that seems to keep the display on:
    https://itunes.apple.com/de/app/stopwatch+/id545654854?l=en&mt=8

  • Is it okay to keep mains connected when battery is fully charged

    is it okay to keep the mains power connected once the battery is fully charged or should i disconnect from the mains power

    There are two things that will kill an apple battery, charge cycles or lack of charge cycles. I've seen dead batteries with hundreds of cycles and others with a few dozen. You have to use it normally, meaning keep it charging, then unplug it and go use  it on the couch as it was designed to be used. I've got two good years out of mine and its still at 83% health. If it starts to die next year its no big deal, $120 for a replacement battery is a drop in the bucket when you consider the original value of the computer and the amount of use I've gotten out of it.

  • 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

  • How can I keep a bean alive forever through out the live of container

    I want to load some important information from DB (which takes long time to calculate) into memory at the start of the app and refresh it periodically and keep it in memory for all jsp/servlets to use.
    - Environment Tomcat / JDK 1.5x
    I was able to do that and keep it alive as long as the app is active, but if the app is idle for a period of time some how the bean is thrown out of memory and when user acceses the page it connects to the DB again. (I have logic that if the contents of bean is empty get it from DB and keeping the data as a hashtable). I am using scope=application in all jsp's that access this bean.
    Any thoughts ?? or any other way to do this (I am almost ready to write to file after long testing...) Please help.
    - Ravi

    You're welcome.
    I think you need to define it in web.xml , as mentioned in this thread
    http://forum.java.sun.com/thread.jspa?forumID=45&threadID=479858
    It's written better on this thread:
    http://forum.java.sun.com/thread.jspa?forumID=45&threadID=739687

  • Unacceptable cloud! Keep CS 6 alive as long as possible!

    Since we got notice, what Adobe did with it´s license model, my colleagues and partner-companies discussed how to go on with that in the future.
    We are all of the same opinion, that this is not acceptable.
    As Adobe knows exactly how to play Monopoly - we feel, that they "force us in their jailcloud" model with no way out.
    They know exactly that they have a nearly standalone situation in a few business-fields. E.g. Acrobat, AE, InDesign...
    And they also know, that, if they once have us in jail, we can´t come out without losing full access to our files (no subscription - no software - no opening of files!)
    No Buy-out solution from Adobe, which makes it possible to have real access to your files after quitting subscription.
    We had a look to many forums around the web & Adobe itself, and we can see that nearly the whole User Community doesn´t want that kind of distribution.
    Only a few (mostly Newcomers) are Pro Cloud.
    Totaly different situation from that Adobe want´s to tell us (...and the market).
    By the side: Nobody understands, why there isn´t a option to get the "cool" cloud OR not (...pay once and lifetime usage - like in the past!).
    So - as nobody wants that - the cause must be: Earn money.
    No word from Adobe about that. Only Marketing Blablabla about the future of cloud-working Blablabla...
    (Not one serious statement! And which really professional company hasn´t it´s own cloud? And why one more cloud from one more sniffing comp.)
    And most of the PRO-Voices didn´t check already, what this model is, when you think it to the end.
    As Adobe is getting more and more arrogant in the last years, we are convinced that the only little chance to make Adobe step back, is, that they see their income flow down.
    (I believe these self loving marketing gurus won´t ever have a look here)
    So our partnership-network decided, that NO ONE will jump on the cloud-jail-train.
    It´s no question, that Adobe will make files from CC-Version incompatible to that ones of CS6 at the start of new features in june or in a very short timeframe afterwards.
    They want to press their cloud into the market as you can see by their methods... Really difficult to find the Selling-Page of CS6.
    Trouble in workflow will be, that if one jumps into Adobes jail, others must follow, if they want to use the CC-files from others afterwards.
    (We know that from past - A new Version of InDesign was never directly compatible to it´s last version for example)
    So the best way to let Adobe feel, what we are thinking about it´s politics is, that as many users as possible decide to do the same.
    KEEP YOUR CS 6 ALIVE AS LONG AS POSSIBLE  - DON´T SUBSCRIBE TO THE CLOUD!
    I also hope that other competitors will see their chance.
    Trust is away. A company which changes it´s distribution such radical will make radical changes in other fields too.
    And Adobe: Stop telling us here, that your cloud-system is cool in any way!!!
    The price was never a matter. But freedom of choice, compatibility and access to my files archive is!
    I - as a ever up to date paying long time user/> 20 yrs - am deeply disappointed!
    Do these guys understand our questions and needs?:
    http://youtu.be/78yigV0GYGQ
    Any answer / statement here?
    Nachricht geändert durch rainschub

    And...
    4.5 stars at the product side resonanz!?
    Only & unique at Adobe.
    Where ever I look to forums all over the web nearly 85 - 90% of the users disagree with Adobes new subsribtion politics.
    I think these product-pages are strictly cencored.
    Also a 2 days old post I made isn´t visible.
    Great pushing products!

  • Keep external process alive after System.exit(0)

    I wish to start Outlook from my Java program and have my own program exit normally but keep alive the Outlook process. Besides, I am not interested in input/output/error streams.
    public class OutlookStarter {
         public static void main(String[] args) throws Exception {
              new ProcessBuilder("cmd", "/c",
                        "\"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();
    }When I run this when Outlook is not started, my program will not exit until I close Outlook.
    I really do not want to close Outlook just to exit my program (my real program has a Swing GUI and users must be able to close it).
    Also when I run this when Outlook is already started, somehow my program DOES exit without closing the new Outlook window.
    EDIT: I can add System.exit(0) and behavior is the same. I can use Runtime.getRuntime().exec and behavior is the same.
    Edited by: Strider80 on Jan 12, 2011 7:27 AM

    Strider80 wrote:
    I wish to start Outlook from my Java program and have my own program exit normally but keep alive the Outlook process. Besides, I am not interested in input/output/error streams.
    public class OutlookStarter {
         public static void main(String[] args) throws Exception {
              new ProcessBuilder("cmd", "/c",
                        "\"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();
    Did you try using [url http://www.computerhope.com/starthlp.htm]start ^[url http://www.computerhope.com/starthlp.htm]Microsoft DOS and command prompt^ ?
              new ProcessBuilder("cmd", "/c",
                        "start \"C:\\Program Files\\Microsoft Office\\Office14\\outlook.exe\"")
                        .start();

  • What keeps this thread alive?

    I have this sun example of how to read data from a serial port http://developer.java.sun.com/developer/releases/javacomm/SimpleRead.java.
    I'm not interested in the serial port stuff but I wonder what exactly keeps the program / the thread alive?
    The entire code:
    * @(#)SimpleRead.java     1.12 98/06/25 SMI
    * Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
    * Sun grants you ("Licensee") a non-exclusive, royalty free, license
    * to use, modify and redistribute this software in source and binary
    * code form, provided that i) this copyright notice and license appear
    * on all copies of the software; and ii) Licensee does not utilize the
    * software in a manner which is disparaging to Sun.
    * This software is provided "AS IS," without a warranty of any kind.
    * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
    * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
    * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND
    * ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY
    * LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE
    * SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS
    * BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
    * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES,
    * HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING
    * OUT OF THE USE OF OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN
    * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
    * This software is not designed or intended for use in on-line control
    * of aircraft, air traffic, aircraft navigation or aircraft
    * communications; or in the design, construction, operation or
    * maintenance of any nuclear facility. Licensee represents and
    * warrants that it will not use or redistribute the Software for such
    * purposes.
    import java.io.*;
    import java.util.*;
    import javax.comm.*;
    public class SimpleRead implements Runnable, SerialPortEventListener
        static CommPortIdentifier portId;
        static Enumeration portList;
        InputStream inputStream;
        SerialPort serialPort;
        Thread readThread;
        public static void main(String[] args)
            portList = CommPortIdentifier.getPortIdentifiers();
            while (portList.hasMoreElements())
                portId = (CommPortIdentifier) portList.nextElement();
                if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL)
                    // print port names to adjust the desired com port
                    System.out.println("Serial Port: " + portId.getName());
                    // if (portId.getName().equals("COM1")) {
                    // this is (hard coded) the port I want to monitor
                    if (portId.getName().equals("COM4")) {
                        SimpleRead reader = new SimpleRead();
        public SimpleRead() {
            try {
                serialPort = (SerialPort) portId.open("SimpleReadApp", 2000);
            } catch (PortInUseException e) {}
            try {
                inputStream = serialPort.getInputStream();
            } catch (IOException e) {}
         try {
                serialPort.addEventListener(this);
         } catch (TooManyListenersException e) {}
            serialPort.notifyOnDataAvailable(true);
            try {
                serialPort.setSerialPortParams(9600,
                    SerialPort.DATABITS_8,
                    SerialPort.STOPBITS_1,
                    SerialPort.PARITY_NONE);
            } catch (UnsupportedCommOperationException e) {}
            readThread = new Thread(this);
            readThread.start();
        public void run() {
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {}
        public void serialEvent(SerialPortEvent event) {
            switch(event.getEventType()) {
            case SerialPortEvent.BI:
            case SerialPortEvent.OE:
            case SerialPortEvent.FE:
            case SerialPortEvent.PE:
            case SerialPortEvent.CD:
            case SerialPortEvent.CTS:
            case SerialPortEvent.DSR:
            case SerialPortEvent.RI:
            case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
                break;
            case SerialPortEvent.DATA_AVAILABLE:
                byte[] readBuffer = new byte[20];
                try {
                    while (inputStream.available() > 0) {
                        int numBytes = inputStream.read(readBuffer);
                    System.out.print(new String(readBuffer));
                } catch (IOException e) {}
                break;
    }The work of the thread is located in the run() method. As long as statements from this method are executed the thread is alive, at least this is what I've read so far in thread HowTos and stuff.
    But:
    public void run() {
            try {
                Thread.sleep(20000);
            } catch (InterruptedException e) {}
        }doesn't contain an endlos loop. It sleeps for a fixed amount of time and then seems to finish. The programm or a thread of the program is still running after these 20 seconds expired and keeps reading data.
    I've also seen a version with 100 ms instead of 20000.
    So now back to my question: Why is this working?
    Why 20000?
    Can somebody enlighten me please?
    I was going to implement an endlos loop to keep such a port monitoring thread alive but since the jave gurus shipped the example this way I'm kinda puzzled.
    Any help is highly appreciated.
    Mat.

    As far as I know the serialEvent() method is a callback. (I think the registered listeners are usually callback aren't they).
    I wish I could rely on this kind of technique. I even read some Thread faqs and howtos over but I couldn't figure out why this should be reliable working.
    Maybe its just because the opening of the port leads to another thread created. The one which monitors the port in the first place and calls the registered listeners. So the 20 seconds may just be a very safe way to let this thread do all its initial work.
    But then ... why doing a seperate thread in SimpleRead?
    Thank you so far for your input,
    Mat.

  • 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.

  • 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.

Maybe you are looking for

  • Data in CSV uploads successfully, but it is not visible after upload.

    Hi, I am using Apex 3.2 on Oracle 11g. This is an imported application for which I am making changes as per my requirements. As I am new to Apex and even SQL, I request forum members to help me with this. Please find below the old code for uploading

  • Bug in Template forms ??

    Wondering if anyone else hit this problem. Running Apex 4.1.0.00.32 Login to Workspace, Goto Application Builder /Choose any application Then goto Shared Components/Templates. Click on any template preview - first time it works fine and shows the tem

  • 'Info' file count varies between original and copied folders

    Unlike Snow Leopard, Lion and Mountain Lion 'Info' counts hidden files in folders (usually .DS files).  However copied folders, often to different locations, computers, etc, do not count to the same total as the original folder.  How can I stop 'Info

  • DSO Activation failed

    HI, Process step dso activation is failed due to Runtime error...I Checked in JOB Log it says ABAP/4 Processor : MESSAGE_TYPE_X and job is cancelled. So i went to ST@@ Tcode and released the dump. and again repeated the failed step.then it again fail

  • 5.1 sound problem in ALC662 rev 1

    i have changed alsa to 6 ch in alsamixer, unmuted all channels. Now when i run speaker-test - c 6 then only front left and front right are operational rest are shown as unused. if i give the full command as with option -D surround51 then no sound com