I had the general view that clean up of resources is done in the finally block,
recently I found this particular code snippet in a class and it was overridi
There are a number of problems with the code in the question, including:
close will prevent the others from executing (as it happens, this doesn't matter in this example because of the peculiar behaviour of Socket).finalize, leave it throwing Throwable (and add @Override). Technically you should also call the super in a finally block.So: Always use finally for these things. finalize is extremely specialised (and PhantomReference are probably better is superficially more complicated).