Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Threads and Synchronization and the fly likes Should I Code A Daemon? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Should I Code A Daemon?" Watch "Should I Code A Daemon?" New topic

Should I Code A Daemon?

John Riool

Joined: Sep 24, 2007
Posts: 5

Looking for some advice. I need to develop a Java application to:
- Query a database looking for new requests (request_status == 'New')
- When a 'New' request is found, instantiate a request object and pass it the request_params
- Update the database (request_status = "Processing")
- Sleep for 5 seconds
- Start entire process over

I think what I am looking for is generally referred to as a daemon. I searched Google for some examples, but cannot find a simple one that I understand -- Kinda new at this.

So, my questions are:
- Am I looking at the best practice for doing this (query, sleep, query, sleep...)?
- Can you give me advice on the best practice?
- Can you point me to an example of the best practice?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19728

John Riool wrote:
- Am I looking at the best practice for doing this (query, sleep, query, sleep...)?

Well, you said those were your requirements. So yes, that's what you have to do.

Or were you asking whether those requirements were a "best practice"? I suppose that would depend on what the actual problem was. If all we have is a set of requirements, with no information about what problem they are intended to solve, it's pretty hard to say whether they solve that problem in a good way.
John Riool

Joined: Sep 24, 2007
Posts: 5
Hi Paul,

The program requirements would be:
- Look for new requests in a database
- When a new request is found, start another program that will generate a report

A couple of notes:
- A new request can show up in the database at any time
- I would like to begin processing new requests with 3-5 seconds of arrival
- More than one new request can be waiting in the database
- The report generating program can take over twenty minutes to complete

So I guess what I am really asking is how should I approach the design of the program?
Have you checked out Aspose?
subject: Should I Code A Daemon?
It's not a secret anymore!