0

I've written a standalone Java (console) application that runs in a cycle of:

  1. Check a database for new tasks to perform
  2. Perform the tasks
  3. Update the database with the results
  4. Sleep for n minutes before waking up to repeat the above

So, it's basically a daemon running in the background. I'd like to add the ability to ask the application, "Hey app, what are you working on right now? Can you give details on your current task? etc.". Ideally, the app would have an easy way to query it for its state, but I'm not sure how to add this. I've looked at Restlet, and considered signal handling, but I'm looking for suggestions from others.

I'm not looking at logging right now since the log files could get very large, and it would be great if the app only generated the info on demand instead of always generating it (I'd like to minimize the impact of this feature on the app's performance).

Has anyone else tried doing this, or have recommendations to make? Thanks in advance.

Community
  • 1
  • 1
Mike
  • 83
  • 6
  • Looks like a *too broad* question. You should reverse the question : batch is easier that a UI, so imagine what kind of interaction you want, with what interface (text only, local GUI, web, etc ...) and simply use worker thread(s) to perform the tasks. – Serge Ballesta Nov 18 '14 at 14:57

2 Answers2

2

There is no reason to fear logging because it might fill up a disk. Look at Log4J, which has log rotation built-in. Furthermore, you can change the log levels at runtime, so you don't have to have verbose logging on all the time, or for all parts of the code.

  • Why add a dependency on Log4J that would make one's application less portable, when the [java.util.logging package](https://docs.oracle.com/javase/8/docs/api/java/util/logging/FileHandler.html) can do the same thing? – VGR Nov 18 '14 at 16:18
  • Because Log4J is more than a file logger, and the query asking for ways of getting varied information out of a running VM. Having used both in several large projects, I'd recommend Log4J. –  Nov 18 '14 at 20:01
  • You seem to be implying that java.util.logging is just a file logger. I respectfully disagree. And it should be mentioned that since it is based on Log4J, it is essentially an integrated version of Log4J. – VGR Nov 18 '14 at 20:18
  • "Having used both in several large projects, I'd recommend Log4J." We can discuss why all day, but not appropriate here. –  Nov 19 '14 at 15:50
1

JMX is a technology that chould help you here; see the MBean Java tutorial. If you're using Spring there's a JMX integration as well.

pmorken
  • 764
  • 4
  • 11