This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes How to Constantly Run Java App on Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How to Constantly Run Java App on Linux" Watch "How to Constantly Run Java App on Linux" New topic

How to Constantly Run Java App on Linux

Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
Hi All,

We have a problem in constantly running a pure Java App on Linux. It seems to be with Linux because it runs as required on our Unix server.

The Application:
We are trying to keep a JMS listener running to listen for incoming MQ messages. We are using a endless while loop to do this. Upon receipt of each message, we spawn a new thread to handle the request. We are using JRE 1.4.2, and we are on a server farm, sharing the server with more than 20 other applications, not owned by us. Also, the Unix servers, on which the app works more consistant is not a server farm.

The Problem:
The app will receive a few messages, if any are sent, but then it seems to "lose" the MQ connection, whether messages are received or not. I can still ps the process created during startup of the app, but the messages are no longer received. Once the app is restared, any waiting messages are received & processed.

Also, I noticed that the interval in which the app dies differs in each of our environments, DEV/QA/PROD, even though it's the same code. In PROD, it is much worse. It will not remain running for more than 5 or 10 mins.

Any help will be greatly appreciated.

Frank Carver

Joined: Jan 07, 1999
Posts: 6920
Naively this should work. I've done stuff like this many times.

I'm guessing that somehow your listener/server is using up some sort of resources (memory, sockets, disk space for logging, whatever).

Can you tell us a bit more about what takes place inside your listen loop? Do you loop "as fast as possible", or do you sleep between checks?

If you are using a reasoably recent version of Java you should also have the nio stuff available, which is probably a much better architecture for this style of application, anyway.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
Hi Frank,

Within the while loop, it sleeps for 2 seconds.

How can nio help? Also, please point me in a direction of learning more about it.

Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15951

JMS is quite happy running in Linux in the JOnAS/Joram, JBoss and IBM WebSphere environments. And, of course, IBM WebSphere MQ carries IBM's own (if somewhat expensive) assurances that it will run. IBM likes Linux.

So I'll have to say that the OS isn't likely the primary issue so much as the software. Since you haven't described what you're using to handle JMS, it's anyone's guess what might be wrong.

Customer surveys are for companies who didn't pay proper attention to begin with.
Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
We are using the following class to receive the JMS listner and create the steady (using while loop) connection via MQQueueConnectionFactory. Please see the class below. This class is called only on startup of the app. The listner just has a standard onMessage method that creates a new thread to handle the request upon receipt. We only send/receive text messages.

Elle Atechsy
Ranch Hand

Joined: Jan 23, 2004
Posts: 96
Also, once the message is received. Our app processes the message by reading an XML file to retreive commands that instructs it to delete &/or write files on the web server docroot within the current server handling the request.
Consider Paul's rocket mass heater.
subject: How to Constantly Run Java App on Linux
Similar Threads
weblogic MqSeries Bridge
Using MQ Client
MDB listening to external MQ in Glassfish
JMS/Websphere MQ and message groups
How to send msgs to more than one MQ Queues