tags:

views:

193

answers:

4

I need to design a Swing application, which will need to send out multiple jobs as customer requested. each job is running the same shell scripts which will take 10-30 mins to return a value. (the jobs are not running on application server or as web services. )then the Swing application will need to decide what to do next according to the return value. my question is if I can use JMS to send out jobs. if not, what do you suggest I look into? multithreading....

Thank you very much!

+2  A: 

JMS can most certainly be used in a Swing based application. If the shell scripts are to be executed on a server by a service that is listening to the JMS queue and respond on another queue or topic.

There is nothing limiting you from using JMS queues or topics in a desktop application.

orj
I got what you said. the shell scripts will not be executed on a server by a service. this is pure swing application. I think I will look into multi-threading. thank you!
mengmenger
You are indeed in need of some multi-threading in your Swing app if you want to run long tasks on the local system.
orj
+2  A: 

JMS is generally used to communicate between processes and between client/server, not really what you're looking for here, unless you're sending them out to a server to be processed, but it doesn't sound like that here. It sounds like you're looking for a work queue, such that a swing app has a button that adds a new task to the queue (where the task is running the shell script). You can then have multiple threads taking tasks of the queue and running the scripts.

Jeff Storey
thank you! I will use multi-threading.
mengmenger
+4  A: 

Multi-threading is the obvious first approximation here. Take a look at SwingWorker, launch the process in a background thread, monitor the progress (as in show the user if it is still running, perhaps even a view into what is being emitted to the console), etc. These are the obvious choices.

What JMS would solve for you (and you would have to find a light weight JMS implementation that would run on the desktop) is to allow for retries and guarantees that the process runs to completion. Something that takes 20 minutes to run in a shell script doesn't sound like it is a candidate for a retry, but if it is, and it is important that the message really get through instead of just having the thread die and the process forgotten if the user closes the java application, then JMS is the type of thing to look at.

Yishai
thank you for your suggestion! I will take a look at SwingWorker.
mengmenger
+1  A: 

You may - or may not - profit from using a job scheduler, like Quartz. Maybe it's overkill, maybe it's just what you need.

Jon Martin Solaas