无法从 cgi 运行 java 命令 [英] unable to run java command from cgi

查看:31
本文介绍了无法从 cgi 运行 java 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能可以在 linux 上使用 tika 读取 doc 文件:

I have this function to read a doc file using tika on linux:

def read_doc(doc_path):
    output_path=doc_path+'.txt'
    java_path='/home/jdk1.7.0_17/jre/bin/'
    environ = os.environ.copy()
    environ['JAVA_HOME'] =java_path
    environ['PATH'] =java_path
    tika_path=java_path+'tika-app-1.3.jar'
    shell_command='java -jar %s --text --encoding=utf-8 "%s" >"%s"'%(tika_path,doc_path,output_path)
    proc=subprocess.Popen(shell_command,shell=True, env=environ,cwd=java_path)
    proc.wait()

当我从命令行运行它时,这个函数工作正常,但是当我使用 CGI 调用相同的函数时,我收到以下错误:

This function works fine when I run it from the command line, but when I call the same function using CGI, I get the following error:

VM 初始化期间发生错误无法预留足够对象堆空间

Error occurred during initialization of VM Could not reserve enough space for object heap

我检查了这个特定错误的先前答案,他们建议增加内存,但这似乎不起作用......我认为这与内存分配无关,而是一些读/写/执行来自 cgi 脚本的特权,知道如何解决这个问题吗?

I checked previous answers for this particular error and they suggest increasing the memory, but this doesn't seem to work...I don't think this has to do with memory allocation, but rather some read/write/execute privilages from the cgi script, any idea how to solve this problem?

推荐答案

您正在内存中加载整个 JVM 实例 &每个单独的 CGI 调用的进程空间.那很糟.很坏.对于性能和内存使用.增加内存分配是一种不能解决真正问题的技巧.核心 java 代码几乎不应该通过 CGI 调用.

You're loading an entire JVM instance within the memory & process space of each individual CGI invocation. That's bad. Very bad. For both performance and memory usage. Increasing memory allocation is a hack that doesn't address the real problem. Core java code should almost never be invoked via CGI.

你会更好:

  • 通过在您的网络服务器中运行一个 java Servlet 来避免 CGI 和 Python,该服务器使用所需的参数直接调用适当的 Tika 类.将用户 url 直接映射到 servlet(通过 Servlet 类上的 @WebServlet("someURL") 注释).
  • 在服务器模式下运行 Tika 并通过 REST 从Python.
  • 将核心 Java 应用程序作为服务器/守护进程单独运行,让它侦听 TCP ServerSocket.通过客户端套接字从 Python 调用.
  • Avoiding both CGI and Python by running a java Servlet within your web server that invokes the appropriate Tika class directly with desired arguments. Map the user url directly to the servlet (via @WebServlet("someURL") annotation on the Servlet class).
  • Running Tika in server mode and invoking it via REST from Python.
  • Running a core java app separately as a server/daemon proces, have it listen on a TCP ServerSocket. Invoke from Python via a client socket.

这篇关于无法从 cgi 运行 java 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆