如何在服务器模式下将 OpenOffice 作为多线程服务使用?
在服务器模式下使用 OpenOffice 是什么体验?我知道 OpenOffice 不是多线程的,现在我需要在我们的服务器中使用它的服务。
我可以做什么来克服这个问题?
我正在使用Java。
What is the experience of working with OpenOffice in server mode? I know OpenOffice is not multithreaded and now I need to use its services in our server.
What can I do to overcome this problem?
I'm using Java.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用当前版本的 JODConverter (3.0-SNAPSHOT),处理多个线程非常容易OOo 无头模式,因为该库现在支持启动多个实例并将它们保存在池中,只需在构建 OfficeManager 实例时提供多个端口号或命名管道即可:
然后,您可以使用该库来转换文档,而无需在后台处理 OOo 实例池:
With the current version of JODConverter (3.0-SNAPSHOT), it's quite easy to handle multiple threads of OOo in headless-mode, as the library now supports starting up several instances and keeping them in a pool, by just providing several port numbers or named pipes when constructing a OfficeManager instance:
You can then us the library e.g. for converting documents without having to deal with the pool of OOo instances in the background:
是的,我使用 OpenOffice 作为文档转换服务器。
不幸的是,解决您的问题的方法是生成一个 OpenOffice 进程池。
commons-pool 分支JODConverter(在移至
code.google.com
之前)已为您实现了此开箱即用功能。Yes, I am using OpenOffice as a document conversion server.
Unfortunately, the solution to your problem is to spawn a pool of OpenOffice processes.
The commons-pool branch of JODConverter (before it moved to
code.google.com
) implemented this out-of-the-box for you.谢谢巴斯蒂安。根据巴斯蒂安的回答,我找到了另一种方法。打开多个端口,它提供创建多线程的访问。但是,如果没有很多端口(足够几个),我们可以通过增加
任务队列超时
来提高性能这里是文档。再说一遍,我们决定不在每个转换过程中start
和stop
officeManager
。最后,我通过这种方法解决了这个任务:当需要转换时,我调用
JODConverter
的convertPDF
。仅当应用程序关闭时才会停止。Thanks Bastian. I found another way, based on Bastian's answer. Opening several ports it provides access to create multithreads. But without many ports(enought several) we can improve performence by increase
task queue timeout
here is a documentation. And one thing again, we decided not tostart
andstop
officeManager
on each convertion process.At the end, I solved this task by this approach:I call
JODConverter
'sconvertPDF
when convertion is need. It will be stopped only when application was down.OpenOffice 可以在无头模式下使用,但它还不能在压力很大的生产环境中处理大量请求。
在无头模式下使用 OpenOffice 存在几个问题:
如建议的,jodconverter 可用于访问 OpenOffice 进程。
http://code.google.com/p/jodconverter/wiki/GettingStarted
OpenOffice can be used in headless mode, but it has not been built to handle a lot of requests in a stressfull production environment.
Using OpenOffice in headless mode has several issues:
As suggested, jodconverter can be used to access the OpenOffice process.
http://code.google.com/p/jodconverter/wiki/GettingStarted
你可以试试这个:
http://www.jopendocument.org/
它是一个基于java的开源库,允许您无需打开 Office 即可处理打开的 Office 文档,从而无需 OOserver。
you can try this:
http://www.jopendocument.org/
its an opensource java based library that allows you to work with open office documents without open office, thus removing the need for the OOserver.
Vlad 关于必须在不同端口上运行多个 OpenOffice 实例的说法是正确的。
我想补充一点,OpenOffice 似乎不稳定。我们在生产环境中运行 10 个实例,并将代码设置为在第一次尝试失败时重试另一个实例。这样,当其中一台 OpenOffice 服务器崩溃(或未崩溃但也不响应)时,生产不会受到影响。由于每天重新启动服务器很痛苦,因此我们正在慢慢将所有文档转换为 JasperReports (详细信息请参阅 iReport)。我不确定您如何使用 OpenOffice 服务器;我们用它来邮件合并(为客户填写表格)。如果您需要将内容转换为 PDF,我建议您使用 iText。
Vlad is correct about having to run multiple instances of OpenOffice on different ports.
I'd just like to add that OpenOffice doesn't seem to be stable. We run 10 instances of it in a production environment and set the code up to re-try with another instance if the first attempt fails. This way when one of the OpenOffice servers crashes (or doesn't crash but doesn't respond either) production is not affected. Since it's a pain to keep restarting the servers on a daily basis, we're slowly converting all our documents to JasperReports (see iReport for details). I'm not sure how you're using the OpenOffice server; we use it for mail merging (filling out forms for customers). If you need to convert things to PDF, I'd recommend iText.