This discussion is archived
1 Reply Latest reply: Jan 11, 2013 10:45 PM by EJP RSS

Why im getting too long time in getting response from server in RMI???

814246 Newbie
Currently Being Moderated
I'm using RMI architecture. On my server side I put this method getRubricHierarchy() which returns the ArrayList of Test class objects. everything is working properly fine.
Im getting response properly, problem is its taking very long time in getting the response. method populate and create ArrayList in 0 second at server side but its taking more than 20 seconds to get response at client side.
My arraylist size is 30,000.

Any suggestions to reduce the time.

below you can see the code.

public List<Test> getRubricHierarchy(String strTree,String gblCombinedRepSectionID,String gblCompleteRepSectionID,String gblCompleteRepertoryID,Map authMap) {
        Connection con=null;
          ResultSet rs = null;
          List<Test> l = new ArrayList<Test>();

          List allList = new ArrayList();

          con = createDBCon();
          rs = con.createStatement().executeQuery("select * from rubric where sectionid='"+gblCombinedRepSectionID+"' order by orders");
          Map parentMap = new HashMap();

          while (rs.next()) {
               Test rNode = new Test();
            String rubrid = rs.getString("id");
               final String desc = rs.getString("name");
               rNode.setRubricName(desc);
               rNode.setRubricID(rubrid);
               rNode.setAuthor(rs.getString("repid"));
               final int levlId = rs.getInt("levelid");
               rNode.setRubLevel(levlId);
               rNode.setCrossRef(rs.getString("CROSSREFERENCE"));
               final String parentID = rs.getString("PARENTID");
               rNode.setParentID(parentID);
               rNode.setSectionID(rs.getString("sectionid"));

               if (parentID.equals("0")) {
                    l.add(rNode);
               }
               allList.add(rNode);

               List rmdyLst = (List) parentMap.get(parentID);
               if (rmdyLst == null) {
                    rmdyLst = new ArrayList();
                    parentMap.put(parentID, rmdyLst);
               }
               rmdyLst.add(rNode);

          }
          rs.close();

          for (Iterator iterator = allList.iterator(); iterator.hasNext();) {
               Test rNodes = (Test) iterator.next();

               List remdyLst = (List) parentMap.get(rNodes.getRubricID());
               if (remdyLst != null) {
                    rNodes.setChildren(remdyLst);
                    for (Iterator iterator2 = remdyLst.iterator(); iterator2.hasNext();) {
                         Test rn = (Test) iterator2.next();
                         rn.setParent(rNodes);
                    }
               }
          }

        }catch(Exception e){
            e.printStackTrace();
        }
          return l;

     }
here is my Test Class
public class Test implements  Serializable,Cloneable , MutableTreeNode{
        private String strRubricID,strOldRubricID,strRubricName,strCrossRef,Author,strParentID,strSectionID;
        private int rubLevel;
        private List remedyList;
        private List children = new ArrayList();
        private Test parent;
        private int order;
        private String AuthorName="";
        private String abbr;
        private String treeType="";
        private int noRem=-1;
        private boolean isAddAsChild=false;
        private String strRubricHie="";
        private String user="";

        public static final Enumeration<TreeNode> EMPTY_ENUMERATION = new Enumeration() {
            public boolean hasMoreElements() {
                return false;
            }

            public TreeNode nextElement() {
                throw new NoSuchElementException("No more elements");
            }
        };

        public Test(){

        }

        public void setUser(String user){
            this.user = user;
        }
        public String getUser(){
            return user;
        }

        public void setRubricHierarchy(String s){
            this.strRubricHie=s;
        }
        public String getRubricHierarchy(){
            return strRubricHie;
        }

        public Test(String treeType){
            this.treeType = treeType;
        }

        public void setAddAsChild(boolean b){
            this.isAddAsChild=b;
        }
        public boolean isAddAsChild(){
            return isAddAsChild;
        }

        public Test getUserObject(){
            return this;
        }

        public  void setRubricID(String id){
            this.strRubricID = id;
        }
        public  String getRubricID(){
            return strRubricID ;
        }
        public  void setOldRubricID(String id){
            this.strOldRubricID = id;
        }
        public  String getOldRubricID(){
            return strOldRubricID ;
        }

        public  void setParent(Test r){
            this.parent = r;
        }
        public  Test getParent(){
            return parent;
        }
        public  void setParentID(String id){
            this.strParentID = id;
        }
        public  String getParentID(){
            return strParentID;
        }

        public  void setSectionID(String id){
            this.strSectionID= id;
        }
        public  String getSectionID(){
            return strSectionID;
        }


        public  void setRubricName(String name){
            this.strRubricName = name;
        }
        public  String getRubricName(){
            return strRubricName;
        }

        public  void setAuthorName(String name){
            this.AuthorName = name;
        }
        public  String getAuthorName(){
            return AuthorName;
        }

        public  void setAuthorAbbrivation(String a){
            this.abbr = a;
        }
        public  String getAuthorAbbrivation(){
            return abbr;
        }


        public void setRubLevel(int rubLevel) {
            this.rubLevel = rubLevel;
        }
        public int getRubLevel() {
            return rubLevel;
        }

        public void setCrossRef(String strCrossRef) {
            this.strCrossRef = strCrossRef;
        }

        public String getCrossRef() {
            return strCrossRef ;
        }

        public void setRemedyList(List remedyList) {
            this.remedyList = remedyList;
        }
        public List getRemedyList() {
            return remedyList;
        }

        public void setAuthor(String Author) {
            this.Author = Author;
        }
        public String getAuthor() {
            return Author;
        }

        public void setChildren(List list) {
            this.children = list;
        }
        public List getChildren() {
            return children;
        }

        public void setOrder(int o){
            this.order = o;
        }
        public int getOrder(){
            return order;
        }

        public void setNumberOfRemedies(int no)
        {
            this.noRem = no;
        }

        public int getNumberOfRemedies()
        {
            return noRem;
        }



        public String toString() {
            String value="";
            value=strRubricName+ " ("+abbr+")";
            return value;
        }

        public Object clone(){
            Test rubric = new Test();
            rubric.Author = Author;
            rubric.children = children;
            rubric.order = order;
            rubric.parent = parent;
            rubric.remedyList = remedyList;
            rubric.rubLevel = rubLevel;
            rubric.strCrossRef = strCrossRef;
            rubric.strParentID = strParentID;
            rubric.strRubricID = strRubricID;
            rubric.strRubricName = strRubricName;
            rubric.strSectionID = strSectionID;

            return rubric;
        }

     @Override
     public TreeNode getChildAt(int paramInt) {
          if (this.children == null) {
               throw new ArrayIndexOutOfBoundsException("node has no children");
          }
          final TreeNode node = (TreeNode) children.get(paramInt);
          return node;
     }

     @Override
     public int getChildCount() {
          if (this.children == null) {
               return 0;
          }
          return children.size();
     }

     @Override
     public int getIndex(TreeNode paramTreeNode) {
          // TODO Auto-generated method stub
          return 0;
     }

     @Override
     public boolean getAllowsChildren() {
          return true;
     }

     @Override
     public boolean isLeaf() {
          return children.isEmpty();
     }

     @Override
     public Enumeration children() {
          if (this.children == null) {
               return EMPTY_ENUMERATION;
          }
          Vector v = new Vector(this.children);
          return v.elements();
     }

     @Override
     public void insert(MutableTreeNode newChild, int paramInt) {
          if (newChild == null) {
               throw new IllegalArgumentException("new child is null");
          }

          MutableTreeNode oldParent = (MutableTreeNode) newChild.getParent();

          if (oldParent != null) {
               oldParent.remove(newChild);
          }
          newChild.setParent(this);
          if (children == null) {
               children = new ArrayList();
          }
          children.add(paramInt, newChild);

     }

     @Override
     public void remove(int childIndex) {
          MutableTreeNode child = (MutableTreeNode) getChildAt(childIndex);
          children.remove(childIndex);
          child.setParent(null);
     }

     @Override
     public void remove(MutableTreeNode aChild) {
          if (aChild == null) {
               throw new IllegalArgumentException("argument is null");
          }

          if (!isNodeChild(aChild)) {
               throw new IllegalArgumentException("argument is not a child");
          }
          remove(getIndex(aChild)); // linear search
     }

     public boolean isNodeChild(TreeNode aNode) {
          boolean retval;

          if (aNode == null) {
               retval = false;
          } else {
               if (getChildCount() == 0) {
                    retval = false;
               } else {
                    retval = (aNode.getParent() == this);
               }
          }

          return retval;
     }

     @Override
     public void setUserObject(Object paramObject) {
          // TODO Auto-generated method stub

     }

     @Override
     public void removeFromParent() {
          MutableTreeNode parent = (MutableTreeNode) getParent();
          if (parent != null) {
               parent.remove(this);
          }
     }

     @Override
     public void setParent(MutableTreeNode paramMutableTreeNode) {
          parent = (Test) paramMutableTreeNode;

     }

     /**
      * Returns the path from the root, to get to this node. The last element in
      * the path is this node.
      *
      * @return an array of TreeNode objects giving the path, where the first
      *         element in the path is the root and the last element is this
      *         node.
      */
     public TreeNode[] getPath() {
          return getPathToRoot(this, 0);
     }

     /**
      * Builds the parents of node up to and including the root node, where the
      * original node is the last element in the returned array. The length of
      * the returned array gives the node's depth in the tree.
      *
      * @param aNode
      *            the TreeNode to get the path for
      * @param depth
      *            an int giving the number of steps already taken towards the
      *            root (on recursive calls), used to size the returned array
      * @return an array of TreeNodes giving the path from the root to the
      *         specified node
      */
     protected TreeNode[] getPathToRoot(TreeNode aNode, int depth) {
          TreeNode[] retNodes;

          /*
           * Check for null, in case someone passed in a null node, or they passed
           * in an element that isn't rooted at root.
           */
          if (aNode == null) {
               if (depth == 0)
                    return null;
               else
                    retNodes = new TreeNode[depth];
          } else {
               depth++;
               retNodes = getPathToRoot(aNode.getParent(), depth);
               retNodes[retNodes.length - depth] = aNode;
          }
          return retNodes;
     }

    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points