در ادامه مقاله قبلیم که شماره یک "نکات و اصول مهم در برنامه نویسی Java/Android" بود، در این مقاله شماره دو همین موضوع رو ارائه میدم. منتها کمی پیشرفته تر...
1- طبق گفته Sun، از دستورات
Runtime.runFinalizersOnExit() استفاده نکنید، اینها منسوخ و Unsafe اعلام شدن:
JAVA-DOC: Because it is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock. While this problem could be prevented if the class whose objects are being finalized were coded to "defend against" this call, most programmers do not defend against it. They assume that an object is dead at the time that its finalizer is called. Further, the call is not "thread-safe" in the sense that it sets a VM-global flag. This forces every class with a finalizer to defend against the finalization of live objects!
Joshua Bloch: Never call System.runFinalizersOnExit or Runtime.runFinalizersOnExit for any reason: they are among the most dangerous methods in the Java libraries.