System.close() and resources
Hi,
in my application I start many threads, and them open files. Those threads are like daemons waiting for changes in those files.
If i.e. a critical error is detected, is valid to finish the app a "System.exit()", or do I have to close every file and stop every thread?
Thanx
[302 byte] By [
txatia] at [2007-11-27 10:48:05]

I was under the impression that System.exit() would close the files and stop the threads? Was I wrong?
Yes, Runtime.addShutdownHook(Thread hook) and related methods exist in version 1.4.2. Do use your favourite search engine for more information.
OleVVa at 2007-7-28 22:24:18 >

OK, shutdown hooks allow you to make a perfect shutdown, I'll use them if necessary.
But what happens with the threads and opened files if I just make a System.exit() ?
Let's assume I just want to release those resources, no other processing. Perhaps I get all that done with the System.exit().
txatia at 2007-7-28 22:24:18 >

> System resources (file handles, sockets etc) get
> released back to the system when Java exits. Streams
> and files don't get closed nicely so you may loose
> any data that has been buffered before being written.
If you are writing to (any of) those files, that is. And haven't called flush(). No problem if you're only reading.
I'm trying to complement the answer to the original poster. I am not trying to argue that just calling System.exit() is a nice and clean solution.
OleVVa at 2007-7-28 22:24:18 >
