title: How to listen a socket in Tomcat(servlet container)?
body: <p>I have to let an web application to listen a socket(<em>ServerSocket</em>), and handle the socket stream.</p>
  
  <p>But the application is just deployed in Tomcat which is just a servlet container, it doesn't have JCA support. And establishing a server socket in servlet thread is unreasonable.</p>
  
  <p>solution 1:</p>
  
  <p>The ugly solution is to write a <strong>standalone java application</strong> to listen socket, then communicate with web server. but it is not a sound solution.</p>
  
  <p>solution 2:</p>
  
  <p>I wrote a <strong>ServletContextListener</strong> which starts to listen socket when contextInitialized(), once receiving a socket, it will be handed by a thread. That means a thread pool is located in ServletContext. Of course, I destroy the thread pool when contextDestroyed.</p>
  
  <p>What do you think about the solutions?</p>