views:

95

answers:

5

I'll need to develop a Java service that is simple because:

  • It only communicates via a TCP socket, no HTTP.
  • It runs on a dedicated server (there are no other services except the basic SSH and such)

Should I make this a standalone service (maybe in something like Java Service Wrapper) or make it run in a container like Tomcat? What are the benefits and detriments of both?

+2  A: 

If you aren't working with HTTP, you will have to build your own connectors for Tomcat. When I've written these types of applications, I've just written them as standard Java applications. On Windows machines, I use a service wrapper that allows them to be part of the Windows startup process. On non-windows machines, you just need to add a start up script.

Jim Rush
+1  A: 

Tomcat doesn't really buy you much if you don't use HTTP.

However, I was forced to move a non-HTTP server to Tomcat for following reasons,

  1. We need some simple web pages to display the status/stats of the server so I need a web server. Java 6 comes with a simple HTTP server but Tomcat is more robust.

  2. Our operation tools are geared to run Tomcat only and standalone app just falls off radar in their monitoring system.

  3. We use DBCP for database pooling and everyone seems more comfortable to use it under Tomcat.

The memory foot-print of Tomcat (a few MBs) is not an issue for us so we haven't seen any performance change since moved to Tomcat.

ZZ Coder
+2  A: 

Using a container (regardless which) buys you that all the details about starting, stopping, scaling, logging etc, which you have to do yourself otherwise, and it is always harder than you think (at least when you reach production).

Especially the scalability is something you need to consider already now. Later it will be much harder to change your mind.

So, if somebody already wrote most of what you need, then use that.

Thorbjørn Ravn Andersen
+1  A: 

Tomcat doesn't sound like a good choice for me in your situation. AFAIK it's primarily made for Servlets and JSPs, and you have neither. You also don't need to deploy multiple applications on your app. server etc. (so no benefit from ".war").

If you need dependency injection, connection pooling, logging, network programming framework etc., there are a lot of good solutions out there and they don't need tomcat.

For example, in my case I went for a standalone app. that used Spring, Hibernate, Netty, Apache Commons DBCP, Log4j etc. These can be easily setup, and this way you have a lot more freedom.

Should you need a HTTP server, maybe embedding Jetty is another option. With this option too, you have more control over the app. and this can potentially simplify your implementation compared to using a tomcat container.

Enno Shioji
A: 

A container can save you from reinventing the wheel in terms of startup, monitoring, logging, configuration, deployment, etc. Also it makes your service more understandable to non-developers.

I wouldn't necessarily go for tomcat, check out glassfish and germonimo as they are more modular, and you can have just the bits the need, and exclude the http server.

We faced a similar decision a while back, and some parts of the system ended up being jsw based, and the others as .war files. The .war option is simpler (well more standard for sure) to build and configure.

David Roussel