Results 1 to 4 of 4
  1. #1
    ansarifar is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default my destructor not working

    in the name of god
    hi to all
    i place a simple code in destructor of class:
    protected void finalize () throws IOException {
    System.out.println("finalize******");
    }
    but it not working, i place another function but there are not working too
    please help me
    i need run specific function at the end of running of main() function
    tanks a lot

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ansarifar View Post
    in the name of god
    hi to all
    i place a simple code in destructor of class:
    protected void finalize () throws IOException {
    System.out.println("finalize******");
    }
    but it not working, i place another function but there are not working too
    please help me
    i need run specific function at the end of running of main() function
    tanks a lot
    Finalizers() are a pest and the jvm doesn't guarantee that it runs them when it exits and dies. Only when the garbage collector puts its claws on them it'll run the finalizers in the objects that have them. There is the Runtime.runFinalizersOnExit(boolean value) method but it is deprecated for good reasons.

    kind regards,

    Jos

  3. #3
    ansarifar is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default how can i run a specific function at the end of main

    how can i run a specific function at the end of main without calling that specific function in main body

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,335
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by ansarifar View Post
    how can i run a specific function at the end of main without calling that specific function in main body
    You may have a look at the Runtime.addShutDownHook( ... ) method you you can just as well call that finalization method yourself at the end of your main( ... ) method because, as I wrote before, the jvm won't do it for you.

    kind regards,

    Jos

Similar Threads

  1. This Is Not Working.
    By FatalSylence in forum New To Java
    Replies: 8
    Last Post: 10-16-2010, 02:15 AM
  2. Why is my Do/While Not working?
    By Meta in forum New To Java
    Replies: 1
    Last Post: 05-11-2010, 06:05 PM
  3. working with JC
    By yuhobebbho in forum New To Java
    Replies: 0
    Last Post: 02-10-2010, 11:22 PM
  4. Replies: 8
    Last Post: 05-28-2008, 07:00 AM
  5. Working With ANT
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 04-26-2007, 08:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •