Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Running Java Processes Question

 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I'm still fairly a novice at Java. I have done mostly web work using WebSphere. What I would like to understand now is: what is needed on a server, that does not have WebSphere or WebLogic, to have a Java application process running in the background?

Brief Overview of Application:
The application needs to run at all times to listen for IBM MQ messages via JMS, once it picks up a message it will further process the request as needed. This is strickly backend processing, so there are no GUIs needed.

Thanks,
Lulu
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know the JMS APIs for receiving messages ... what happens when a message arrives? Does JMS call a method on a handler you provide or something like that?

I'd probably have one thread that picks up incoming messages as quickly as possible and just puts them into a blocking queue. Another thread can pull items from the queue and process them. Using two thread helps assure the code that accepts incoming messages is not busy processing one long enough to miss another one.

All this is provided in JDK 5 with the BlockingQueue interface and the thread pooling utilities. A thread pool with only one thread would do the job with very little effort on your part. If messages come in faster than one thread can process them, adding more threads might help.

See BlockingQueue and ThreadPoolExecutor. If you're in an older JDK, read up on the concepts and if they look interesting look up a 3rd party package like the Apache Commons Thread Pool or Doug Lea's packages.
 
Elle Atechsy
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The thread pooling package was not something we thought about due to the web applications using WebSphere which handled the thread pool. This is very helpful. Thanks, Stan.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic