0

I wonder how can I close (kill) Java running program via eclipse in an orderly manner. I have some classes which implements the finalize method. when I click on the red button (terminate), the finalize method is not invoke.

So how can I close running java program via eclipse, such as the finalize methods will be invoked ?

I need this option in order to close the connections in an orderly manner.

1 Answers1

2

So how can I close running java program, such as the finalize methods will be invoked?

It is not possible to force objects to be finalized.

It is certainly not possible to force reachable objects to be finalized on JVM shutdown.

You will need to find some other way to implement your requirement. For example, you could keep a list of all connections that are currently open, and use a shutdown hook to explicitly close them all.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216