This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Why Java creators have left it upto the scheduler to execute when to execute garbage collector thread?
Its probably based on the assumption that your average developer will not know nearly enough to do GC efficiently. Its also one of the basic aims of Java that the programmer should be shielded form such low-level (and quite often error prone) tasks so they can concentrate of the actually business problem, rather then the internal machinations of a processes environment.
Its probably based on the assumption that your average developer will not know nearly enough to do GC efficiently
Well as i have learned thats not the prominent reason behind not giving the programmer a chance to force the GC run.
The reason for Sun to leave it at the mercy of JVM is... (1) GC in Java 1.1 was a seperate thread with a higher priority and so it will run with fairly even manner with the main thread etc. This deterioted the program efficiency as it became a overhead for the scheduler to run GC everytime. The Garbage Collection cycle is still a very expensive operation.
(2) So from later versions onwards they made the GC thread with a lower priority. And it assures that there is no overhead on the JVM in managing an extra cycle(instruction/machine cycle) for the operation og GC alway. It may run or never run. But it is most probable to run whenever the memory is packed to almost full and to an extend it would avoid OutOfMemoryException.
Being a Java programmer you are given an advantage of getting insulated from the CPU related system level operations. So leave that work load to whoever concerned(JVM or OS).