Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2012
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default Contains of arraylist are not getting deleted after executing the program

    I have written a program for stingtokenizer,in which I am using arraylists to holad the values.If I run the program for the first time it is not giving any exception,when I compile the program again the arraylist is holding both the old value and the new value.My doubt is why is the arraylist not releasing the previous value after completing the execution of program?

    example:
    ar is the arraylist

    1st compilation,

    ar.add(sptspt);

    it is printing the value sptspt when executed for the first time.


    2nd compilation,

    ar.add(sptgnr);

    same arraylist is printing sptspt,sptgnr after second execution.


    if I clear the arraylists at the end of program then I am not getting this kind of problem.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    758
    Rep Power
    8

    Default Re: Contains of arraylist are not getting deleted after executing the program

    Can you post your code for us to see exactly how your program works?

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Contains of arraylist are not getting deleted after executing the program

    Whatever made you think this question belongs in the Other IDEs section? I'm moving it to New to Java.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Join Date
    Feb 2012
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default Re: Contains of arraylist are not getting deleted after executing the program

    I forgot to mention I am working on weblogic workshop,Actually there is no error in code,when I run the same logic in eclipse its working fine.
    I think there is some problem with the garbage collection of JVM.

    I am taking a XML as input and pass the values to a procedure and taking the output of procedure and passing the output in the form of XML.

    here is the part of code

    Java Code:
    public void tokenizing(){
            
            if(message_substring.equals("FAILURE")){
                
                responseXML.getInvValResp().setOutputMessage(message);
                
            }
            
            else{
            
                responseXML.getInvValResp().setOutputMessage(message);
            
                log.info("Message added");
            
                StringTokenizer stringTokenizerdn = null;
            
                stringTokenizerdn = new StringTokenizer(strdn, "+");
            
                while (stringTokenizerdn.hasMoreTokens()) {
                
                    dslam_name.add(stringTokenizerdn.nextElement());
                
                }
            
                StringTokenizer stringTokenizerip = null;
            
                stringTokenizerip = new StringTokenizer(strip, "+");
            
                while (stringTokenizerip.hasMoreTokens()) {
                
                    dslam_ip.add(stringTokenizerip.nextElement());
                
                }
            
                StringTokenizer stringTokenizervn = null;
            
                stringTokenizervn = new StringTokenizer(strvn, "+");
            
                while (stringTokenizervn.hasMoreTokens()) {
                
                    vendor_name.add(stringTokenizervn.nextElement());
                
                }
            
                log.info(dslam_name);
            
                log.info(dslam_ip);
            
                log.info(vendor_name);
            
                StringTokenizer stringTokenizercn = null;
            
                stringTokenizercn = new StringTokenizer(strcn, "+");
            
                StringTokenizer stringTokenizerct = null;
            
                stringTokenizerct = new StringTokenizer(strct, "+");        
            
                for(int i = 0;i<dslam_name.size();i++) {
                
                     log.info("in for loop");
                 
                     try{   
                    
                        responseXML.getInvValResp().addNewDSLAMInfo();             
                 
                        responseXML.getInvValResp().getDSLAMInfoArray(i).setDSLAMName(dslam_name.get(i).toString());
                 
                        responseXML.getInvValResp().getDSLAMInfoArray(i).setDSLAMIP(dslam_ip.get(i).toString());
                 
                        responseXML.getInvValResp().getDSLAMInfoArray(i).setVendorName(vendor_name.get(i).toString());
                 
                    }
                    catch(Exception ex){
                    
                        log.error(ex.toString());
                    
                    }
                
                    String strc = (String) stringTokenizercn.nextElement();
                 
                    String strt = (String) stringTokenizerct.nextElement();
                 
                    StringTokenizer stringTokenizerc = null;
                
                    stringTokenizerc = new StringTokenizer(strc, ",");             
                 
                    StringTokenizer stringTokenizert = null;
                    
                    stringTokenizert = new StringTokenizer(strt, ",");
                 
                    while (stringTokenizerc.hasMoreTokens() & stringTokenizert.hasMoreTokens()){
                     
                        log.info("In while loop");
                     
                        cards.add(stringTokenizerc.nextElement());
                     
                        card_type.add(stringTokenizert.nextElement());
                     
                        log.info(cards);
                     
                        log.info(card_type);
                     
                    }
                 
                    for(int j = 0;j < cards.size();j++){
                    
                        log.info(cards.get(j));
                        
                        log.info(card_type.get(j));
                     
                        try{   
                        
                            responseXML.getInvValResp().getDSLAMInfoArray(i).addNewCARD();                
                        
                            responseXML.getInvValResp().getDSLAMInfoArray(i).getCARDArray(j).setCardNo(cards.get(j).toString());
                     
                            responseXML.getInvValResp().getDSLAMInfoArray(i).getCARDArray(j).setCardType(card_type.get(j).toString());
                        
                        }
                     
                        catch(Exception e){
                        
                            log.error(e.toString());
                        
                        }                 
                     
                        log.info("loop executed");                
                     
                    }
                 
                 
                 
                 cards.clear();
                 
                 card_type.clear();          
                
                }
            
            }
            
           dslam_name.clear();
           dslam_ip.clear();                         //I am using clear() method to clear the arraylist.
           vendor_name.clear();
           
           //System.gc();
            
            
            log.info("****Response XML****"+responseXML);
            
        }
    Last edited by anudeepmandati; 07-27-2012 at 12:44 PM. Reason: to mark the text as code

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Contains of arraylist are not getting deleted after executing the program

    Please use [code] tags[/code] when posting code as that lot is unreadable without them.

    "I think there is some problem with the garbage collection of JVM."

    I very, very, *very* much doubt that is the case.

    After you've added the code tags you'll need to point out the array causing the problem, and state what you are seeing and why that is wrong.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #6
    Join Date
    Feb 2012
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default Re: Contains of arraylist are not getting deleted after executing the program

    dslam_name
    dslam_ip
    vendor_name
    cards
    card_type

    these arraylists are creating problems.

    Ya even I think there is some problem with garbage collection of my JVM.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Contains of arraylist are not getting deleted after executing the program

    Where are those array lists declared?

    You also haven't said what the exact problem is.
    What are you seeing and what do you think you should be seeing?
    How are you determining something is going wrong?
    Is this a multi-threaded environment?

    Give us something to work with here...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    Join Date
    Feb 2012
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default Re: Contains of arraylist are not getting deleted after executing the program

    If I run the program without the last 3 clear() methods I should get the following XML response

    Java Code:
    <InvValResp xmlns="http://www.bsnl.com/InvValResp.xsd">
      <OutputMessage>SUCCESS : DSLAM is available</OutputMessage>
      <DSLAM_info>
        <DSLAM_name>SPTGNR_10.250.184.114</DSLAM_name>
        <DSLAM_IP>10.250.184.114</DSLAM_IP>
        <VendorName>UTSTARCOM</VendorName>
        <CARD>
          <card_no>CARD NO 1</card_no>
          <card_type>ADSL</card_type>
        </CARD>
        <CARD>
          <card_no>CARD NO 2</card_no>
          <card_type>ADSL</card_type>
        </CARD>
        <CARD>
          <card_no>CARD NO 3</card_no>
          <card_type>ADSL</card_type>
        </CARD>
      </DSLAM_info>
    </InvValResp>
    running code for first time

    input is

    dslam_name:[SPTGNR_10.25.14.114]

    dslam_ip:[10.25.14.114]

    vendor_name:[UTSTARCOM]


    output is

    dslam_name:[SPTGNR_10.25.14.114]

    dslam_ip:[10.25.14.114]

    vendor_name:[UTSTARCOM]


    but if I run the program more than once
    dslam_name,dslam_ip and vendor_name these arraylists are holding the previous values also

    input is
    dslam_name:[SPTMTL_10.56.28.114]

    dslam_ip:[10.56.28.114]

    vendor_name:[NSN]


    output is

    dslam_name:[SPTGNR_10.25.14.114, SPTMTL_10.56.28.114]

    dslam_ip:[10.25.14.114, 10.56.28.114]

    vendor_name:[UTSTARCOM, NSN]

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Contains of arraylist are not getting deleted after executing the program

    OK.
    Now where are those arrays declared?

    You say "without the last 3 clear() methods". Well, if you;re not emptying the arrays then it's not surprising it adds onto the existing array.

    Also, "but if I run the program more than once". Now, what exactly do you mean by this? Because this implies two separate launches of your application, which would not give the result you are claiming. So I can only assume you mean "call the method more than once".

    You also haven't answered what environment this is.

    Come on, help us to help you...this gets rather frustrating if you don't give us the information to actually help.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  10. #10
    Join Date
    Feb 2012
    Location
    Bangalore
    Posts
    6
    Rep Power
    0

    Default Re: Contains of arraylist are not getting deleted after executing the program

    Sorry Tolls,I am working in weblogic workshop,weblogic is our application server.
    I will explain what I am doing.
    I am working in a telecom project.
    This is the scenario,
    We get the request for inventory details(exchange name) in the form of a XML and we have to give the response XML with DSLAM card details present in that XML.
    To do this purpose we write a Java Process Definition(JPD)
    The module that sends the request XML calls our JPD and our JPD executes the procedure and sends back the response to the same module.
    request XML is

    Java Code:
    <InvValReq xmlns="http://www.bsnl.com/InvValReq.xsd" >
    	<ExchangeName>SPTGNR</ExchangeName>
    </InvValReq>
    the expected response XML is,

    Java Code:
    <InvValResp xmlns="http://www.bsnl.com/InvValResp.xsd">
      <OutputMessage>SUCCESS : DSLAM is available</OutputMessage>
      <DSLAM_info>
        <DSLAM_name>SPTGNR_10.250.184.114</DSLAM_name>
        <DSLAM_IP>10.250.184.114</DSLAM_IP>
        <VendorName>UTSTARCOM</VendorName>
        <CARD>
          <card_no>CARD NO 1</card_no>
          <card_type>ADSL</card_type>
        </CARD>
        <CARD>
          <card_no>CARD NO 2</card_no>
          <card_type>ADSL</card_type>
        </CARD>
        <CARD>
          <card_no>CARD NO 3</card_no>
          <card_type>ADSL</card_type>
        </CARD>
      </DSLAM_info>
    </InvValResp>

    When I test the JPD with that request XML I am getting the expected response XML,but when I test the JPD again I am getting error as the arraylists are holding previous values also.
    If I clean the application and test again its working fine.

    What my doubt is whenever we run a java program,the objects are created in the memory and they are deleted after completion of execution,this deletion process is done by JVM(garbage collection).But in this case that is not happening,the arraylist objetcs are holding the previous values that is what is surprising me,I have never come across this kind of issue till now.

    I hope I have provided necessary information.

    I know what is the problem but I want to know why this is happening now,why not before?

    Thanks Tolls for sparing your time.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: Contains of arraylist are not getting deleted after executing the program

    So, where are those arrays declared?
    Because I'm betting they've been stuck as an attribute on a servlet or some other singleton which means they get updated on each request.
    These aren't being "run" each time, they are being called.
    The app is there and running as long as the server is up.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Deleted post: Java Grading Program
    By Fubarable in forum Forum Lobby
    Replies: 0
    Last Post: 07-02-2012, 12:27 PM
  2. Executing query from java program
    By ashu000 in forum Advanced Java
    Replies: 4
    Last Post: 06-27-2011, 11:27 AM
  3. Executing an external java program
    By arunsubramanian in forum Advanced Java
    Replies: 5
    Last Post: 02-06-2009, 07:49 AM
  4. help-executing the program
    By j2vdk in forum New To Java
    Replies: 6
    Last Post: 08-30-2008, 09:18 PM

Tags for this Thread

Posting Permissions

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