Results 1 to 2 of 2
  1. #1
    coolFrenzi is offline Member
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

    Default Improve the slow running time

    Hello,
    My program accesses MS Access with a few 1000 rows and also uses 3 LIFO structures. It takes over 10 hrs to run completely (I killed the program after running for 10 hrs and getting partial result). Please have a look at the following method and suggest me ways to improve on the running time.

    Java Code:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    
    public class count 
    {
     LinkedList<Integer> queue1 = new LinkedList<Integer>();
     //LinkedList<String> queue2 = new LinkedList<String>();
     LinkedList<Integer> queue3 = new LinkedList<Integer>();
    
     java.sql.Connection conn;
     ResultSet rs;
     PreparedStatement psmt;
    
     PrintStream ps;
     int level;
     int num=0;
    
     public void getEventChild()
     {
    
      try
       {
        FileOutputStream fout = new FileOutputStream ("write.txt");
        ps=new PrintStream(fout);
       }//end try
       catch (IOException e)
       {
        System.err.println ("Unable to read from file");
       }
    
      try
      {
       
       conn = connectDB.getAccessDBConnection();
       String query="select r.conceptid1, c.FULLYSPECIFIEDNAME from Relationship r, concept c where c.conceptid=r.conceptid1 and r.characteristicType = 0 and r.conceptid2 = ?";
       psmt = conn.prepareStatement(query);
       int cid=272379006;//Event concept ID'
       level=0;//concept level in hierarchy
       recurseChild(cid, level);
      }
      catch(SQLException s) 
      {
       System.out.println(s);
      } 
      finally  
      {
       if(conn != null) 
       {
        try 
        {
         conn.close();
        } 
        catch(SQLException ignore) 
        {}
       }
      }//end finally  
    
     }//end func()
    
    
     public void recurseChild(int id, int level)
     {
    
      try 
      {
          psmt.setInt(1, id);
       
        if(psmt.execute()) 
        {
         
         rs=psmt.getResultSet();
         level++;
    
         if(rs!=null)
         while(rs.next())
         {
            num++;
            int ss1=rs.getInt(1);
            //String ss2=rs.getString(2);
            
            queue1.add(ss1);//conceptid
            //queue2.add(ss2);//term
            queue3.add(level);
         }
         rs.close();
         
         if(!queue1.isEmpty())
         {
          int i1=queue3.removeLast();
          int s1=queue1.removeLast();
          //System.out.println(num);
          
          recurseChild(s1, i1);
         }
    
        }  //end if
        
       else 
       {
        System.out.println("DDL executed successfully");
       }
    
      } //end try
      
      catch(SQLException s) 
      {
       System.out.println(s);
      } 
        
     }//end recursiveChild()
    
    
     public static void main(String args[]) 
     {
      count ev = new count();
      ev.getEventChild();
     
     }//end main
         
    
    }

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Use an iterative loop rather than recursion to cut the method call overhead.
    Use a faster SQL engine than MSAccess.
    Try and simplify your query, or the process by which you are reaching your goal. The fewer the number of calls from Java to SQL the better.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

Similar Threads

  1. how to improve my security?
    By anthrax in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-13-2009, 09:08 AM
  2. Calculating the Running time
    By JordashTalon in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 10:32 PM
  3. Replies: 1
    Last Post: 01-12-2009, 08:59 AM
  4. Replies: 25
    Last Post: 06-28-2008, 05:08 PM
  5. how to improve the performance of JWS?
    By dinesh kaushik in forum Java Applets
    Replies: 0
    Last Post: 11-21-2007, 08:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •