Results 1 to 11 of 11
- 07-27-2012, 08:21 AM #1
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 6
- Rep Power
- 0
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.
- 07-27-2012, 08:59 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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?
Website: Learn Java by Examples
- 07-27-2012, 10:06 AM #3
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.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 07-27-2012, 11:52 AM #4
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 6
- Rep Power
- 0
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
- 07-27-2012, 12:14 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 07-27-2012, 12:39 PM #6
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 6
- Rep Power
- 0
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.
- 07-27-2012, 12:52 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 07-27-2012, 01:12 PM #8
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 6
- Rep Power
- 0
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
running code for first timeJava 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>
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]
- 07-27-2012, 01:40 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
- 07-27-2012, 02:01 PM #10
Member
- Join Date
- Feb 2012
- Location
- Bangalore
- Posts
- 6
- Rep Power
- 0
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
the expected response XML is,Java Code:<InvValReq xmlns="http://www.bsnl.com/InvValReq.xsd" > <ExchangeName>SPTGNR</ExchangeName> </InvValReq>
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.
- 07-27-2012, 03:37 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
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.
Similar Threads
-
Deleted post: Java Grading Program
By Fubarable in forum Forum LobbyReplies: 0Last Post: 07-02-2012, 12:27 PM -
Executing query from java program
By ashu000 in forum Advanced JavaReplies: 4Last Post: 06-27-2011, 11:27 AM -
Executing an external java program
By arunsubramanian in forum Advanced JavaReplies: 5Last Post: 02-06-2009, 07:49 AM -
help-executing the program
By j2vdk in forum New To JavaReplies: 6Last Post: 08-30-2008, 09:18 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks