20 Replies Latest reply on Mar 25, 2015 6:40 PM by dng

    Java thread is being aborted,Channel 33537 destroyed because of client's inactivity

    kjelavankal

      I built a java service interface to PI that quries PI servers in frequent intervals of 1-2 minutes to get data and store it in a application database.

      My code

                   Connection string - jdbc:pisql://XXXXXX/ Integrated Security=SSPI;Persist Security Info=False;Data Source= XXXXX

                    plist.put("DCA", "SAVE");

                    plist.put("user", prop.getProperty("WPIUN"));

                    plist.put("password", prop.getProperty("WPIPW"));

                   Class.forName(driver).newInstance();    

                   conn = DriverManager.getConnection(connectionString,plist);

              

      I have the above code in a try and catch block to catch any unexpected errors

       

      try

      {

          Connection string - jdbc:pisql://XXXXXX/ Integrated Security=SSPI;Persist Security Info=False;Data Source= XXXXX

                    plist.put("DCA", "SAVE");

                    plist.put("user", prop.getProperty("WPIUN"));

                    plist.put("password", prop.getProperty("WPIPW"));

                   Class.forName(driver).newInstance();    

                   conn = DriverManager.getConnection(connectionString,plist);

                   PreparedStatement pstmt = conn.prepareStatement (sqlStmt.toString());

                   ResultSet rs = pstmt.executeQuery();

      } catch (Exception e) {  

              System.out.println("ERROR OBTAINING DATABASE CONNECTION: " + e.getMessage());       

              haveConnection = false;

              error = true;     

      }finally {

            if (conn != null && error) {

              try {conn.close();} catch (Exception e) {return null;}

            }else if (error){return null;}

       

      The code works fine continually for several hours/days . However after 1-2 days randomly I get an error from the PI server that breaks my thread and stops my service.

       

      When I look into the Pi logs from the PI SDK utlity i see the following Message at the time my service stopped

       

      "Channel 33537 destroyed because of client's inactivity"

       

      The java program keeps pinging the PI server and gets the following messages

      Channel has been established

      Succesfully connected to server

      Chanell has been closed by the client 

       

      Then suddenly at one particular instance it returns teh message "Channel 33537 destroyed because of client's inactivity" and that breaks the java thread.

       

      Questions

      1) Why is this error occuring randomly?

      2) How can i modify my java program that ignores such exception and continue without breaking the program?

       

       

      Thanks

      Kiran

        • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
          dng

          Hi Kiran,

           

          JDBC client does periodic health check with the PI SQL DAS. Getting the channel destroyed messages means the PI JDBC client didn't clean up normally or the communication was bad (e.g. application crash, dropped packets in network). If the client later refers to this destroyed Channel ID, PI SQL DAS rejects this request and client gets an exception.

           

          A few questions to help with the troubleshooting:

          • What version of JDBC driver are you using? There is a known issue (62996) in JDBC 1.1 (resolved in 1.3) that might improve this re-connection behavior.
          • What is your system architecture? Do you have JDBC client and PI SQL DAS installed on the same or separate machine? Do you have multiple JDBC clients using the same PI SQL DAS server?
          • Do you see the following error message on the PI SQL DAS machine around the time when the issue occurred? "[Orb.Channel] The channel is not registered on server." It will be helpful to look at the PI JDBC logs on the client machine, as well as PI message logs on the PI SQL DAS machine as well as the PI Data Archive machine.
          • What was the exception thrown by the java application?
          • Have you seen this error occurred more than once?
          • Was there any network outage, or restart of the PI SQL DAS or PI server?
            • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
              kjelavankal
              • What version of JDBC driver are you using? There is a known issue (62996) in JDBC 1.1 (resolved in 1.3) that might improve this re-connection behavior.I installed PI JDBC 2012
              • What is your system architecture? Do you have JDBC client and PI SQL DAS installed on the same or separate machine? Do you have multiple JDBC clients using the same PI SQL DAS server?Java App on the same server machine with PI SQL DAS   . No multiple JDBC clients
              • Do you see the following error message on the PI SQL DAS machine around the time when the issue occurred? "[Orb.Channel] The channel is not registered on server." It will be helpful to look at the PI JDBC logs on the client machine, as well as PI message logs on the PI SQL DAS machine as well as the PI Data Archive machine. - NO I don't see that message
              • What was the exception thrown by the java application? No Exception was not thrown . It just stopped working  in spite of a try & catch block it did not catch the exception. This is my main issue . I want to handle such errors so that my java service continues to run ignoring this issue.
              • Have you seen this error occurred more than once? YES several times its random ,occurs in about 2-3 days after running without interruption.
              • Was there any network outage, or restart of the PI SQL DAS or PI server? NO
              • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                bshang

                Hi Kiran,

                 

                You may be experiencing issue(s)

                99525 - A crash can occur when multiple Web Service threads make concurrent calls to PISDK 

                113582 - Flooding pisqldas with many short lived requests crashes PISDK

                 

                To properly diagnose it, I would suggest setting up a crash dump, such as with WER Collecting User-Mode Dumps (Windows), being sure to choose Full Dump. Then, open up a case with Tech Support who can review the dump and properly determine if the issue above applies.

                 

                There are a few workarounds to try, but I would suggest getting the crash dump first and see if the issue above applies.

                1) Add another instance of SQL DAS (Each client connects to a different server)

                                -Each client connects to a different SQL DAS instance, avoiding concurrent SDK calls.

                2) Specify the same Session ID (positive integer) in the JDBC connection string for each client machine

                                -This assumes each client uses the same set of credentials when connecting to SQL DAS

                                -This causes all requests to SQL DAS to become serialized, avoiding the known issue.

                    • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                      bshang

                      I edited my post and updated the links. Can you try the new links above and see if they work?

                        • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                          kjelavankal

                          Barry,

                           

                          I have setup dumps . Will send you the results but before that wanted to check the following

                           

                          We setup Jconsole to trace the error and this is what we are getting

                           

                          Name: Thread-4
                          State: RUNNABLE
                          Total blocked: 808 Total waited: 52

                          Stack trace:
                          com.osisoft.rdsa.Connection.Destroy(Native Method)
                          com.osisoft.rdsa.Connection.close(Connection.java:135)
                             - locked com.osisoft.rdsa.Connection@1b0baa8
                          com.osisoft.jdbc.ConnectionImpl.close(ConnectionImpl.java:107)
                          com.aep.csii.dao.oracle.OraclePiDAO.getPiData(OraclePiDAO.java:203)
                          com.aep.csii.server.datacollection.DataCollectionManager.doPIDataCollection(DataCollectionManager.java:1000)
                          com.aep.csii.server.datacollection.DataCollectionManager.run(DataCollectionManager.java:461)
                          java.lang.Thread.run(Thread.java:662)

                           

                          Name: Finalizer
                          State: RUNNABLE
                          Total blocked: 204 Total waited: 204

                          Stack trace:
                          com.osisoft.rdsa.Command.Destroy(Native Method)
                          com.osisoft.rdsa.Command.destroy(Command.java:92)
                             - locked com.osisoft.rdsa.Command@1ae80fa
                          com.osisoft.rdsa.Command.finalize(Command.java:97)
                          java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
                          java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
                          java.lang.ref.Finalizer.access$100(Finalizer.java:14)
                          java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

                           

                          The thread is hanging trying to close the connection 

                           

                          how can we prevent this ?

                           

                          Logs from PI SDK utility

                           

                          3/12/2015 5:20:55 PM, 0, Information, Channel 20539 destroyed because of client's inactivity., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:20:33.423 PM, 4, Information, Successfully connected to server XXXX as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:54.91701 PM, 0, Information, Channel 20541 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:54.505 PM, 0, Information, Channel 20538 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:53.511 PM, 0, Information, Channel 20540 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:50.46301 PM, 0, Information, Channel 20540 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:45.73601 PM, 0, Information, Channel 20539 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:43.009 PM, 0, Information, Channel 20536 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:42.011 PM, 0, Information, Channel 20535 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:41.011 PM, 0, Information, Channel 20537 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:40.11601 PM, 4, Information, Successfully connected to server OHAEPHQAS561 as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:40.091 PM, 0, Information, Channel 20538 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:39.86301 PM, 4, Information, Successfully connected to server XXXX  as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:39.839 PM, 0, Information, Channel 20537 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:35.33401 PM, 0, Information, Channel 20536 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:30.82401 PM, 0, Information, Channel 20535 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:29.007 PM, 0, Information, Channel 20533 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:28.00401 PM, 0, Information, Channel 20534 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:26.39301 PM, 0, Information, Channel 20534 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:19:22.11301 PM, 0, Information, Channel 20533 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:25.511 PM, 0, Information, Channel 20530 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:24.51201 PM, 0, Information, Channel 20529 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:23.51401 PM, 0, Information, Channel 20531 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:22.50601 PM, 0, Information, Channel 20532 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:16.845 PM, 0, Information, Channel 20532 has been established (User:; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:12.47501 PM, 0, Information, Channel 20531 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:12.19 PM, 0, Information, Channel 20530 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:12.011 PM, 0, Information, Channel 20527 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:11.013 PM, 0, Information, Channel 20526 has been closed by client., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:10.47101 PM, 0, Information, Channel 20529 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                          3/12/2015 5:18:10.009 PM, 0, Information, Channel 20528 has been closed by client., pisqldas64, , , , , , , , , , ,

                           

                           

                          On my java code i have done several things

                          On the Main function before the thread is being initalized i have the following

                           

                               Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

                                    public void uncaughtException(Thread t, Throwable e) {
                                        System.out.println("Caught " + e);
                                    }
                                });

                           

                          Then on the Main function that calls the  other  functions to get data from PI I have setup try & catch

                           

                          } catch (Exception e) {

                                  Logging.logException(e, "ERROR - Unable to complete data collection loop.");

                                }

                                catch (Throwable ex) {

                                      System.out.println("Server Error:" + ex.toString());

                                      ex.printStackTrace();

                                      return;

                                  }

                              }

                           

                          and on the functions that make the PI database calls i have declared those functions as throws Exception{)

                           

                          However INSPITE of all this when we encounter a "Channel 20539" destroyed error from PI the thread just keeps hanging without closing or be handled by the exception handler

                           

                          My code

                           

                          String driver = "com.osisoft.jdbc.Driver";

                                    Properties plist = new Properties();

                                    plist.put("user",prop.getProperty("PIUN"));

                                    plist.put("password",prop.getProperty("PIPW"));  

                                   Class.forName(driver).newInstance();    

                                    conn = DriverManager.getConnection(connectionString,plist);

                                    PreparedStatement pstmt = conn.prepareStatement (sqlStmt.toString());

                                              ResultSet rs = pstmt.executeQuery();

                           

                           

                           

                           

                          I am more focused about handling this error gracefully and continuing my thread . It is fine if i get this error if I am able to handle it and continue.

                           

                           

                          Any help would be highly appreciated.

                           

                      • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                        dng

                        Hi Kiran,

                         

                        Did PI SQL DAS service ever crash when you are experiencing the issue? You can look at the Windows event viewer to determine this. The two WI's that Barry pointed out should cause a crash in PI SQL DAS, and the workaround will prevent a crash (if that was indeed the reason). Did you set up PI SQL DAS service to automatically restart?

                         

                        Note that you can use stateless connections to PI SQL DAS, such that your application will not need to restart even following a PI SQL DAS crash. The downside is that stateful commands such as “USE catalog” cannot be used. But this can be easily addressed by using fully qualified names in queries. 24x7 applications such as yours can benefit from the option to survive a PI SQL DAS restart. The stateless connection is used when the following keyword is added to the connection string: “Stateless Connection=true;”.

                          • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                            kjelavankal

                            NO PISQLDAS does not crash.

                             

                            How can I gracefully handle such issues. My java try catch is not handling such errors. It just breaks my thread and crashes. I want my jave code to gracefully handle it and continue.

                             

                            I am using the following exception handling

                             

                              } catch (Exception e) {

                                    Logging.logException(e, "ERROR - Unable to complete data collection loop.");

                                  }

                                  catch (Throwable ex) {

                                        System.out.println("Server Error:" + ex.toString());

                                        ex.printStackTrace();

                                        return;

                                    }

                                }

                             

                            I dont mind much if I can gracefully handle this issue .

                             

                            I will try Stateless Connection=true; and let you know.

                              • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                dng

                                Hi Kiran,

                                 

                                If your application crashed, can you give us the error messages as well as the stack trace when it happens? Does the windows event viewer contain messages about your application crash? A crash dump will also be helpful. We can then identify where exactly is the issue occurring.

                                 

                                Please let me know how your test with "Stateless Connection=true" goes.

                                  • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                    kjelavankal

                                    Hi Daphne,

                                     

                                    Thanks for your reply.

                                     

                                    I have setup dumps . Will send you the results but before that wanted to send you the following

                                     

                                    We setup Jconsole to trace the error and this is what we are getting. I ran this with "Stateless Connection=true"

                                     

                                    Name: Thread-4
                                    State: RUNNABLE
                                    Total blocked: 808 Total waited: 52

                                    Stack trace:
                                    com.osisoft.rdsa.Connection.Destroy(Native Method)
                                    com.osisoft.rdsa.Connection.close(Connection.java:135)
                                       - locked com.osisoft.rdsa.Connection@1b0baa8
                                    com.osisoft.jdbc.ConnectionImpl.close(ConnectionImpl.java:107)
                                    com.aep.csii.dao.oracle.OraclePiDAO.getPiData(OraclePiDAO.java:203)
                                    com.aep.csii.server.datacollection.DataCollectionManager.doPIDataCollection(DataCollectionManager.java:1000)
                                    com.aep.csii.server.datacollection.DataCollectionManager.run(DataCollectionManager.java:461)
                                    java.lang.Thread.run(Thread.java:662)

                                     

                                    Name: Finalizer
                                    State: RUNNABLE
                                    Total blocked: 204 Total waited: 204

                                    Stack trace:
                                    com.osisoft.rdsa.Command.Destroy(Native Method)
                                    com.osisoft.rdsa.Command.destroy(Command.java:92)
                                       - locked com.osisoft.rdsa.Command@1ae80fa
                                    com.osisoft.rdsa.Command.finalize(Command.java:97)
                                    java.lang.ref.Finalizer.invokeFinalizeMethod(Native Method)
                                    java.lang.ref.Finalizer.runFinalizer(Finalizer.java:83)
                                    java.lang.ref.Finalizer.access$100(Finalizer.java:14)
                                    java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:160)

                                     

                                    The thread is hanging trying to close the connection 

                                     

                                    how can we prevent this ?

                                     

                                    Logs from PI SDK utility

                                     

                                    3/12/2015 5:20:55 PM, 0, Information, Channel 20539 destroyed because of client's inactivity., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:20:33.423 PM, 4, Information, Successfully connected to server XXXX as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:54.91701 PM, 0, Information, Channel 20541 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:54.505 PM, 0, Information, Channel 20538 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:53.511 PM, 0, Information, Channel 20540 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:50.46301 PM, 0, Information, Channel 20540 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:45.73601 PM, 0, Information, Channel 20539 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:43.009 PM, 0, Information, Channel 20536 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:42.011 PM, 0, Information, Channel 20535 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:41.011 PM, 0, Information, Channel 20537 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:40.11601 PM, 4, Information, Successfully connected to server OHAEPHQAS561 as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:40.091 PM, 0, Information, Channel 20538 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:39.86301 PM, 4, Information, Successfully connected to server XXXX  as piusers | PIWorld, pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:39.839 PM, 0, Information, Channel 20537 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:35.33401 PM, 0, Information, Channel 20536 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:30.82401 PM, 0, Information, Channel 20535 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:29.007 PM, 0, Information, Channel 20533 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:28.00401 PM, 0, Information, Channel 20534 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:26.39301 PM, 0, Information, Channel 20534 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:19:22.11301 PM, 0, Information, Channel 20533 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:25.511 PM, 0, Information, Channel 20530 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:24.51201 PM, 0, Information, Channel 20529 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:23.51401 PM, 0, Information, Channel 20531 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:22.50601 PM, 0, Information, Channel 20532 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:16.845 PM, 0, Information, Channel 20532 has been established (User:; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:12.47501 PM, 0, Information, Channel 20531 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:12.19 PM, 0, Information, Channel 20530 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:12.011 PM, 0, Information, Channel 20527 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:11.013 PM, 0, Information, Channel 20526 has been closed by client., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:10.47101 PM, 0, Information, Channel 20529 has been established (User: ; IP: ; Transport: HTTPS)., pisqldas64, , , , , , , , , , ,

                                    3/12/2015 5:18:10.009 PM, 0, Information, Channel 20528 has been closed by client., pisqldas64, , , , , , , , , , ,

                                     

                                     

                                    On my java code i have done several things

                                    On the Main function before the thread is being initalized i have the following

                                     

                                         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

                                              public void uncaughtException(Thread t, Throwable e) {
                                                  System.out.println("Caught " + e);
                                              }
                                          });

                                     

                                    Then on the Main function that calls the  other  functions to get data from PI I have setup try & catch

                                     

                                    } catch (Exception e) {

                                            Logging.logException(e, "ERROR - Unable to complete data collection loop.");

                                          }

                                          catch (Throwable ex) {

                                                System.out.println("Server Error:" + ex.toString());

                                                ex.printStackTrace();

                                                return;

                                            }

                                        }

                                     

                                    and on the functions that make the PI database calls i have declared those functions as throws Exception{)

                                     

                                    However INSPITE of all this when we encounter a "Channel 20539" destroyed error from PI the thread just keeps hanging without closing or be handled by the exception handler

                                     

                                    My code

                                     

                                    String driver = "com.osisoft.jdbc.Driver";

                                              Properties plist = new Properties();

                                              plist.put("user",prop.getProperty("PIUN"));

                                              plist.put("password",prop.getProperty("PIPW"));  

                                             Class.forName(driver).newInstance();    

                                              conn = DriverManager.getConnection(connectionString,plist);

                                              PreparedStatement pstmt = conn.prepareStatement (sqlStmt.toString());

                                                        ResultSet rs = pstmt.executeQuery();

                                     

                                     

                                     

                                     

                                    I am more focused about handling this error gracefully and continuing my thread . It is fine if i get this error if I am able to handle it and continue.

                                     

                                     

                                    Any help would be highly appreciated.

                                      • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                        dng

                                        Hi Kiran,

                                         

                                        When you sent over the dump files,can you also give me the version of PI SDK and PI SQL DAS? Can you also send me the full java code? Thanks.

                                          • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                            kjelavankal

                                            Hi,

                                             

                                            I was not able to get any crash dumps yet. The folder is empty.

                                             

                                            PISDK - > PI SDK 2010 R2 -v2.0.50727

                                            PISQLDAS-->PI-SQL-DAS_1.3.0.0251

                                             

                                            There is a datacollection service that runs every few seconds . StartProcess method calls it
                                            On the run() method of the dataCollectionmanage.java it calls a function doPiDataCollection();
                                            I have listed each functions from start to end.
                                            void startProcesses(Properties prop) {
                                                System.out.println(" Server processes starting...");
                                                // Code to handle uncaught expections added to handle unexpected PI errors
                                                 Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
                                                      public void uncaughtException(Thread t, Throwable e) {
                                                          System.out.println("Server Error:" + e.toString());
                                                            e.printStackTrace();
                                                      }
                                                  });   
                                                //Start the Main Server
                                                startMainServer();
                                                System.out.println("SERVER STARTED!");
                                              }

                                            private void startMainServer() {  
                                                  //Start the Data Collection Manager
                                                  System.out.println("Starting the Data Collection Manager...");
                                                  dataCollectionManager = new DataCollectionManager();
                                                  dataThread = new Thread(dataCollectionManager);
                                                  dataThread.start();   
                                              }

                                            DataCollectionManager
                                            public void run() {
                                                System.out.println("Data Collection Manager Started.");
                                                while (Server.SERVER_RUNNING) {
                                                  try {
                                              
                                                       doPIDataCollection();
                                                      } catch (Exception e) {
                                                        Logging.logException(e, "ERROR - Unable to complete data collection loop.");
                                                      }
                                                      catch (Throwable ex) {
                                                        System.out.println("Server Error:" + ex.toString());
                                                        ex.printStackTrace();
                                                        return;
                                                      }
                                                    }
                                                   System.out.println("Data Collection Manager shutdown.");
                                               }

                                            private void doPIDataCollection() throws Exception{  
                                            try
                                               {  
                                                  piDAO.getPiData(XXX,XXX,XXX,XXX,XXX);
                                                } catch (Exception e) {
                                                    Logging.logException(e, "ERROR - Unable to complete PI data collection loop.");
                                                  }
                                                  catch (Throwable ex) {
                                                        System.out.println("Server Error:" + ex.toString());
                                                        ex.printStackTrace();
                                                        return;
                                                    } 
                                              }

                                            public IntervalDataList getPiData(XXX,XXX,XXX,XXX,XXX) throws Exception {
                                              try {
                                               
                                                conn = PiConnectionPool.getConnection(piServer, piCredentials);
                                                
                                                //get descriptors from PI
                                                PreparedStatement pstmtD = conn.prepareStatement(discriptorlistSqlSmt.toString());
                                                ResultSet rsDescriptorList = pstmtD.executeQuery();
                                                rsDescriptorList.close();
                                                pstmtD.close();
                                                 
                                                //get Actual data
                                                PreparedStatement pstmt = conn.prepareStatement(sqlStmt.toString());
                                                ResultSet rs = pstmt.executeQuery();
                                                rs.close();
                                                pstmt.close();
                                                } catch (Exception e) {
                                                        //Logging.logSQLException(e);
                                                        e.printStackTrace();
                                                        Logging.logException(e, "Unable to connect to  PI: ");
                                                    } finally {
                                                        if (conn != null) {
                                                            try {
                                                                conn.close();
                                                            } catch (Exception e) {
                                                            }
                                                        }
                                                    }
                                                return list;
                                                }

                                            public static synchronized Connection getConnection(XX,XX) throws Exception {
                                                Connection conn = null;
                                                boolean haveConnection = false;
                                                boolean error = false;
                                                while (!haveConnection) {
                                                try {
                                                   
                                                    
                                                     
                                                      String driver = "com.osisoft.jdbc.Driver";
                                                      Properties plist = new Properties();
                                                      plist.put("user",XXX);
                                                      plist.put("password",XX);            
                                                      Class.forName(driver).newInstance();    
                                                      conn = DriverManager.getConnection(connectionString,plist);         
                                                    if (conn == null) {        
                                                      haveConnection = false;
                                                      error = true;
                                                      return null;         
                                                    } else {
                                                      haveConnection = true;
                                                    }
                                                    //Catch any  Exceptions caused
                                                  } catch (Exception e) {  
                                                    //System.out.println("ERROR OBTAINING DATABASE CONNECTION: " + e.getMessage());       
                                                    haveConnection = false;
                                                    error = true;      
                                                  }finally {
                                                  if (conn != null && error) {
                                                    try {conn.close();} catch (Exception e) {return null;}
                                                  }else if (error){return null;}
                                                }     
                                                }
                                                if (!error) {
                                                  System.out.println("Connection was obtained.");
                                                }
                                                return conn;
                                              }
                                            • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                              kjelavankal

                                              There were couple of places where Connection cleanup was missing . After making those changes . It seems to work good . Thanks for your help.

                                            • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                              michaelh

                                              Hi Kiran,

                                              regarding the PI SDK log:

                                              can you explain how these many channels are created and closed again? (If yes, a why would be a curious next question)
                                              I see three channels open in parallel usually, closed actively a few seconds later in reverse order?

                                              I cannot see this in the code snippets you posted.

                                               

                                              These log messages come from PISQLDAS receiving connection.open and close requests.

                                              "Channel 20539 destroyed because of client's inactivity" appears when a PI JDBC client abandons an open connection, after a while.
                                              ( If the client is still active and assumes the connection still open, it should catch an Exception, and need to open a new connection )

                                                • Re: Java thread is being aborted,Channel 33537 destroyed because of client's inactivity
                                                  kjelavankal

                                                  Hi Michael,

                                                   

                                                  At least 3-4 channels are created and closed in a minute .We are doing this to recreate the "Channel destroyed" error. That error occurs rarely but when it occurs it hangs the java service down which is not good . when we create several channels quickly we are able to recreate that error consistently .

                                                  we are trying to recreate the error so we can determine exactly what's happening and work out a way to gracefully handle it, when it will (apparently) inevitably happen in production. We are trying to find out how to avoid it or gracefully handle it.
                                                  I am not able to catch the error and the service hangs forceing me to restart the process again. I am not much concerned about the error but I am looking for  a way to gracefully handle it.
                                                  There is a datacollection service that runs every few seconds . StartProcess calls it
                                                  On the run() method of the dataCollectionmanage.java it calls a function doPiDataCollection();
                                                  I have listed each functions from start to end.

                                                  void startProcesses(Properties prop) {

                                                      System.out.println(" Server processes starting...");

                                                      // Code to handle uncaught expections added to handle unexpected PI errors
                                                       Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {

                                                            public void uncaughtException(Thread t, Throwable e) {
                                                                System.out.println("Server Error:" + e.toString());
                                                                  e.printStackTrace();
                                                            }
                                                        });   

                                                      //Start the Main Server
                                                      startMainServer();

                                                      System.out.println("SERVER STARTED!");
                                                    }


                                                  private void startMainServer() {  

                                                        //Start the Data Collection Manager
                                                        System.out.println("Starting the Data Collection Manager...");
                                                        dataCollectionManager = new DataCollectionManager();
                                                        dataThread = new Thread(dataCollectionManager);
                                                        dataThread.start();   
                                                    }


                                                  DataCollectionManager

                                                   

                                                   

                                                  public void run() {

                                                      System.out.println("Data Collection Manager Started.");

                                                      while (Server.SERVER_RUNNING) {
                                                        try {
                                                    
                                                             doPIDataCollection();
                                                            } catch (Exception e) {
                                                              Logging.logException(e, "ERROR - Unable to complete data collection loop.");
                                                            }
                                                            catch (Throwable ex) {
                                                              System.out.println("Server Error:" + ex.toString());
                                                              ex.printStackTrace();
                                                              return;
                                                            }
                                                          }
                                                         System.out.println("Data Collection Manager shutdown.");
                                                     }


                                                  private void doPIDataCollection() throws Exception{  
                                                  try
                                                     {  

                                                        piDAO.getPiData(XXX,XXX,XXX,XXX,XXX);

                                                      } catch (Exception e) {
                                                          Logging.logException(e, "ERROR - Unable to complete PI data collection loop.");
                                                        }
                                                        catch (Throwable ex) {
                                                              System.out.println("Server Error:" + ex.toString());
                                                              ex.printStackTrace();
                                                              return;
                                                          } 
                                                    }


                                                  public IntervalDataList getPiData(XXX,XXX,XXX,XXX,XXX) throws Exception {
                                                    try {

                                                     
                                                      conn = PiConnectionPool.getConnection(piServer, piCredentials);
                                                      
                                                      //get descriptors from PI
                                                      PreparedStatement pstmtD = conn.prepareStatement(discriptorlistSqlSmt.toString());
                                                      ResultSet rsDescriptorList = pstmtD.executeQuery();
                                                      rsDescriptorList.close();
                                                      pstmtD.close();
                                                       
                                                      //get Actual data
                                                      PreparedStatement pstmt = conn.prepareStatement(sqlStmt.toString());
                                                      ResultSet rs = pstmt.executeQuery();
                                                      rs.close();
                                                      pstmt.close();
                                                      } catch (Exception e) {
                                                              //Logging.logSQLException(e);
                                                              e.printStackTrace();
                                                              Logging.logException(e, "Unable to connect to  PI: ");
                                                          } finally {
                                                              if (conn != null) {
                                                                  try {
                                                                      conn.close();
                                                                  } catch (Exception e) {
                                                                  }
                                                              }
                                                          }
                                                      return list;
                                                      }


                                                  public static synchronized Connection getConnection(XX,XX) throws Exception {
                                                      Connection conn = null;
                                                      boolean haveConnection = false;
                                                      boolean error = false;
                                                      while (!haveConnection) {
                                                      try {
                                                         
                                                          
                                                           
                                                            String driver = "com.osisoft.jdbc.Driver";
                                                            Properties plist = new Properties();
                                                            plist.put("user",XXX);
                                                            plist.put("password",XX);            
                                                            Class.forName(driver).newInstance();    
                                                            conn = DriverManager.getConnection(connectionString,plist);         
                                                          if (conn == null) {        
                                                            haveConnection = false;
                                                            error = true;
                                                            return null;         
                                                          } else {
                                                            haveConnection = true;
                                                          }
                                                          //Catch any  Exceptions caused
                                                        } catch (Exception e) {  
                                                          //System.out.println("ERROR OBTAINING DATABASE CONNECTION: " + e.getMessage());       
                                                          haveConnection = false;
                                                          error = true;      
                                                        }finally {
                                                        if (conn != null && error) {
                                                          try {conn.close();} catch (Exception e) {return null;}
                                                        }else if (error){return null;}
                                                      }     
                                                      }
                                                      if (!error) {
                                                        System.out.println("Connection was obtained.");
                                                      }
                                                      return conn;
                                                    }