title: Close resources before exiting JFrame and TCP communication in Java
body: <p><strong>1.</strong>
  I'm writing a chat based application on TCP communication.
  I'm using NetBeans and I want to add functionality to the default EXIT_ON_CLOSE when exiting JFrame.
  The reason of course is because I want to clean resources and end threads safely.
  How can I call a method that clear resources and only then close the JFrame safely and end the process.</p>
  
  <p><strong>2.</strong>
  I need to implement the server side. The server has List/HashMap/Queue of 'Socket' with their chat nick-names. Is there any simple design pattern to do it correctly because I don't want to re-invent the wheel.</p>
  
  <p>thanks.</p>