Results 1 to 4 of 4

Thread: Calling communicator.destroy() from a JVM shutdown hook

  1. #1
    Alexey Romanov is offline Registered User
    Name: Alexey Romanov
    Organization: Focus Media
    Project: Smart card controllers
    Join Date
    Apr 2010
    Posts
    23

    Calling communicator.destroy() from a JVM shutdown hook

    Would it make sense to call communicator.destroy() in a JVM shutdown hook to make sure that it will get called whatever happens? Or can it take unreasonably long time?

    Also, is there a reason finally blocks are not used for destroying a communicator in Java/C# client examples in the Reference Manual?

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,196
    Hi,

    Yes, you can use a shutdown hook to destroy the communicator. You can also use the Ice.Application helper class and it will take care of installing a hook to either destroy or shutdown the Ice communicator. See this link for more information on the Ice.Application class.

    The communicator destroy call can take time to complete. If for example your Ice application is a server and there are some invocations being dispatched, destroy will wait until all the dispatched invocations are done. If there are still opened Ice connections, destroy will also gracefully close these connections and wait for the connections to be closed by the peer (which might also take some time if the peer doesn't promptly close the connections).

    The examples in the manual which are destroying the communicator could use finally blocks, there are no specific reasons for not using them.

    Cheers,
    Benoit.

  3. #3
    Alexey Romanov is offline Registered User
    Name: Alexey Romanov
    Organization: Focus Media
    Project: Smart card controllers
    Join Date
    Apr 2010
    Posts
    23
    Ice.Application looks useful. Except I have a GUI client, so need to show exception message in the window instead of the console. Is there a way to use Ice.Application with my own exception handler?

  4. #4
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi,

    It's not possible to set your own exception handler in Ice.Application. In fact, we usually recommend against using Ice.Application in a GUI client. For example, GUI clients often cannot block their main thread, but invoking Application.main() will block the calling thread until its communicator is destroyed.

    You can certainly copy the portions of Ice.Application that you find useful into your own class. Also, if you haven't done so already, you should familiarize yourself with the "dispatcher" facility (see section 32.10.7 here). It makes life simpler when writing graphical Ice applications.

    Regards,
    Mark

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. GUI hangs on communicator shutdown
    By n2503v in forum Help Center
    Replies: 3
    Last Post: 10-21-2011, 08:20 AM
  2. Is it safe to call Communicator.destroy() multiple times?
    By Alexey Romanov in forum Help Center
    Replies: 2
    Last Post: 05-25-2010, 07:09 AM
  3. python: shutdown of communicator hangs
    By hiasl in forum Help Center
    Replies: 6
    Last Post: 02-05-2007, 01:50 PM
  4. Bug in GC at Communicator::destroy()
    By acbell in forum Bug Reports
    Replies: 2
    Last Post: 02-23-2006, 11:23 PM
  5. Notification on communicator shutdown
    By stephan in forum Help Center
    Replies: 11
    Last Post: 10-13-2004, 04:38 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
  •