简体   繁体   English

Java Web应用程序中的并发

[英]Concurrency in Java Web Application

I have created a Java Web Application that asks the user to upload an ARF File, converts it to MP4 and saves it on the server and the user is then sent an email with the link of the new MP4 file. 我创建了一个Java Web应用程序,要求用户上传ARF文件,将其转换为MP4并将其保存在服务器上,然后向用户发送一封包含新MP4文件链接的电子邮件。 The conversion takes place by calling a VB Script from the command line. 通过从命令行调用VB脚本进行转换。 This script converts all the ARF files that are located in a desired directory to MP4 format. 该脚本将位于所需目录中的所有ARF文件转换为MP4格式。

The application has been working well but I have noticed one thing. 该应用程序运行良好,但我注意到了一件事。 It does not work when one person (using one computer) runs the application and say the file is in the process of being converted (ie the user is waiting for the email). 当一个人(使用一台计算机)运行该应用程序并说文件正在转换过程中(即用户正在等待电子邮件)时,它不起作用。 At this stage if another user (using another computer) tries to run the application at the same time, the conversion process gets disrupted and it stops the previous conversion. 在此阶段,如果另一个用户(使用另一台计算机)尝试同时运行该应用程序,则转换过程将被中断,并且它将停止先前的转换。

I tried testing the VB Script by running it, waiting for a video to be converting and then running it again. 我尝试通过运行VB脚本,等待视频转换然后再次运行来测试VB脚本。 I noticed the same thing. 我注意到了同样的事情。

Was wondering if there is a way to make my application concurrent so that it can run independently ie more than one person can run it at the same time. 想知道是否有一种方法可以使我的应用程序并发,以便它可以独立运行,即可以有多个人同时运行它。

Thank you 谢谢

The limitation here is the limitations of the VB script. 这里的限制是VB脚本的限制。 Can you (for example) generate a different filename for each so that it works in parallel? 您是否可以(例如)为每个文件生成不同的文件名,使其并行工作?

If not then you will have to queue up the requests and then have some code that processes the next request from the queue one at a time. 如果不是,那么您将必须使请求排队,然后有一些代码一次处理队列中的下一个请求。

It sounds like the code that invokes the VB script is the bottleneck. 听起来,调用VB脚本的代码是瓶颈。 I take it that the file conversion process would take some amount of time so that what you want is have the processing started in a background thread and terminate the java session. 我认为文件转换过程将花费一些时间,因此您需要在后台线程中启动处理并终止Java会话。 The first thing that came to my mind is Quartz job framework. 我想到的第一件事是Quartz工作框架。 You can trigger a Quartz job that does the processing and emailing and each Quartz job is running on its own thread. 您可以触发一个进行处理和发送电子邮件的Quartz作业,并且每个Quartz作业都在自己的线程上运行。 http://quartz-scheduler.org/documentation http://quartz-scheduler.org/documentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM