开发者

can JMS used in Java Swing App

开发者 https://www.devze.com 2022-12-20 07:27 出处:网络
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

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!


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.


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.


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消