> I hava a class in wich I initialize a resource like this:
>
[quoted text clipped - 7 lines]
>
> How can I do to free the ressource when the program exists ?
First of all, are you sure you need to? It's extremely rare to find a
resource on any modern operating system that isn't automatically
reclaimed when a process exits.
If you need to do this, the safest way is generally to create an outside
watchdog process that waits for this one to end and then reclaims the
resources from the outside. Alternatively, add the logic to the normal
exit case and then add a note in the documentation about manually
cleaning up the resource if it is missed.

Signature
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
dpr - 24 May 2004 15:45 GMT
Chris Smith a écrit :
>>I hava a class in wich I initialize a resource like this:
>>
[quoted text clipped - 9 lines]
>
> First of all, are you sure you need to?
Actually the allocation of ressource results, at the end, in sending a
initialization command to a specific hardware. I need to send a
"terminate" command.
It's extremely rare to find a
> resource on any modern operating system that isn't automatically
> reclaimed when a process exits.
[quoted text clipped - 4 lines]
> exit case and then add a note in the documentation about manually
> cleaning up the resource if it is missed.
Thanks.
Pedro - 29 May 2004 18:32 GMT
> Chris Smith a écrit :
>
[quoted text clipped - 28 lines]
>
> Thanks.
You can add a shutdown hook. See
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html#addShutdownHook(j
ava.lang.Thread)
The Thread object passed as parameter will be executed when the Java virtual machine exits.
Regards,
Pedro