Web Hosting Tomcat, Java, JSP, Servlets, J2EE, PHP, MySQL

Cheap web hosting provider

28
Oct

Black Art of Java Game Programming by Joel

Black Art of Java Game Programming by Joel Fan Sams, Macmillan Computer Publishing ISBN: 1571690433 Pub Date: 11/01/96 Previous Table of Contents Next Automatic Garbage Collection (Reclaiming Unused Memory) Next we need to talk a little about garbage collection. This is a term you may have heard used in reference to Java before. In older-generation languages, you had to allocate memory to objects and variables manually. Once you were done with them, you had to deallocate the affected portions of memory to make them available to the rest of your programs. This was a very tricky business, because if you allocated too much, or didn t deallocate enough, you could easily run out of memory. Even worse, if you deallocated too soon, and then tried to access your variable or object, it was gone and the computer would likely crash! This was no fun at all. Luckily, Java has automatic garbage collection, which carefully monitors when objects are no longer being used and then reclaims the memory they once used. You will probably never be aware of this process, or ever have to interact with it, but you should understand how it works. To demonstrate this concept, we are going to have sClientGroup do some garbage collection of its own. The cleanHouse( ) Method Periodically, sClientGroup has to check to make sure that any inactive threads in the Vector are removed (we will teach each sClientThread to make itself inactive if it loses the connection from its client). This is why we made sure that sClientGroup was a thread, so it can run an infinite loop, and call cleanHouse() every once in a while. Here is the cleanHouse() method that does the actual garbage collecting work: /* go through the Vector, and search for “dead” Threads (which are disconnected) and then remove them from the list */ public void cleanHouse() { int x; sClientThread tempThread; for (x=0; x
Note: If you are looking for cheap and quality provider to host and run your java application check Astra java hosting services

Comments are closed.

Home | About Us | Compare Plans | Standard Hosting | Business Hosting | Java Tomcat Hosting | Support | FAQ | Order Now!

Powered by Omnicus java hosting services. All rights reserved.
Entries (RSS) and Comments (RSS).