jagadeesh.macherla

JVM Crashing - concurrent connections - PI JDBC

Discussion created by jagadeesh.macherla on Oct 4, 2010
Latest reply on Oct 7, 2010 by jagadeesh.macherla

Hi,

 

I am trying to run the following program which is crashing JVM and PI SQL DAS. Does anyone know what i am doing wrong. Is there any limit on number of concurrent connections that i can make? I have PI SQL DAS and jdbc on the same machine.

package com.spacetimeinsight.testdata.pi;

import java.sql.*;
import java.util.Properties;

public class GetSnapConcurrent {
 private static int count = 0;

 public static void main(String[] args) {
  // arguments: java getSnap url2 mytagsearchpattern
  // Example: java getSnap mydas mypi sin%
  Connection con = null;
  final String url = "jdbc:pisql://" + args[0] + "/Data Source=" + args[1] + "; Integrated Security=SSPI";
  final String driver = "com.osisoft.jdbc.Driver";
  Statement stmt;
  ResultSet rs;
  final Properties plist = new Properties();
  plist.put("user", "user");
  plist.put("password", "password");

  // plist.put("LogConsole", "True");  // optionally switch on debug info
  // plist.put("LogLevel", "3");       // 3=Fine
  try {
   Class.forName(driver).newInstance();
   for (int i = 0; i < 20; i++) {

    Thread t = new Thread(new Runnable() {

     public void run() {

      for (int j = 0; j < 2; j++) {
       Connection con = null;
       Statement stmt = null;
       ResultSet rs = null;
       try {
        count++;
        System.out.println("before trying to get the connection[" + (count) + "]");
        con = DriverManager.getConnection(url, plist);
        System.out.println("after trying to get the connection [" + (count) + "], con = [" + con + "]");
        stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
        DatabaseMetaData md = con.getMetaData();
        System.out.println(md.getDriverName() + " " + md.getDriverVersion());
        System.out.println(md.getDatabaseProductName());
        System.out.println(md.getDatabaseProductVersion() + "\n");
        String query = "SELECT tag, value FROM pisnapshot WHERE tag like 'sinu*'";
        //rs = stmt.executeQuery(query.toUpperCase());
        //PreparedStatement pstmt = con.prepareStatement(query);
        //pstmt.setString(1, "Generation used in load for*");
        //System.out.println(pstmt);
        rs = stmt.executeQuery(query);
        while (rs.next()) {
         String value, tag;
         tag = rs.getString(1);
         value = rs.getString(2);
         System.out.println(tag + " " + value);
        }
       } catch (Exception e) {
        e.printStackTrace();
       } finally {
        try {
         if (rs != null)
          rs.close();
        } catch (SQLException e) {

        }
        try {
         if (stmt != null)
          stmt.close();
        } catch (SQLException e) {

        }
        try {
         System.out.println("before trying to close  the connection[" + con + "]");
         if (con != null)
          con.close();
        } catch (SQLException e) {

        }
       }
      }
     }
    });
    t.start();
   }
  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   if (con != null) {
    try {
     con.close();
    } catch (SQLException e) {
     e.printStackTrace();
    }
   }
  }

 }
}

Regards,

 

Jagadeesh

Attachments

Outcomes