Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java program goes to the end but the GC is still working.

 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a strange problem about the GC.

The program is a long live process with start time and end time. I executes the program using java -verbose:gc [Java class]. Once the program reaches end time, the program will go to the end. However, it looks like it doesn't go to the end because I still can see the GC message keeps coming out, i.e. [GC 892K->339K(5056K), 0.0023834 secs].

Please suggest what is going on.


Thanks
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be the GC cycle ran after your program completed and released references to objects ? Why is this a problem ?
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because suppose the program is supposed to the end after the last line of code. However, the GC log message is still displaying.
Like :

Class XXX {

public static main(String args[]) {
while(true) {
//loop
}

System.out.println("End");
}


If End is printed, that means the program is going to the end, but the GC message is still displaying. I think this is absolutely problem, right?


Please help

 
Viktor Kubinec
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java application process doesn't end when main method is completed. It ends when all threads are completed. I don't know what are you doing in your while loop but if new Threads were started there this could be the reason.
 
Benson Fung
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your valuable information, Viktor.

Let me give more information. What the loop does is

1. Use Runtime.exec to execute another java process
2. At the same time it creates two threads to monitor the above process Error Stream and Input Stream. The thread looks like the following :





Please help


Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic