[英]Java process on Mac OSX seems to “hang” when invoked via webserver, but OK from the commandline
I have a very strange situation where a Java process seems to hang when called via Apache/PHP, but OK when invoked from the command line. 我有一个非常奇怪的情况,当通过Apache / PHP调用时,Java进程似乎挂起,但是从命令行调用时可以正常。 I spent hours debugging this, no avail. 我花了几个小时调试这个,没有用。 Any and all thoughts welcome! 欢迎任何和所有的想法!
Situation: I have a .class file (without the original Java code) that reads an input file, processes the read information, and writes a report on stdout. 情况:我有一个.class文件(没有原始Java代码),它读取输入文件,处理读取信息,并在stdout上写入报告。 The Java code doesn't read stdin, and only writes stdout. Java代码不读取stdin,只写stdout。 I wrapped this in a tiny Perl script that basically just execs "java -cp /path/to/classfile MyJavaProgram /path/to/inputfile/to/process". 我把它包装在一个很小的Perl脚本中,基本上只执行“java -cp / path / to / classfile MyJavaProgram / path / to / inputfile / to / process”。 That way I can invoke it from the command line for testing, this works like a charm. 这样我就可以从命令行调用它进行测试,这就像一个魅力。 Next, I try to invoke this from PHP using popen(), and there Java just hangs. 接下来,我尝试使用popen()从PHP调用它,并且Java只是挂起。 I see the Perl process in the ps list, and Java; 我在ps列表中看到了Perl进程和Java; but the Java process waits forever. 但Java进程永远等待。 Once I kill it, the webserver page continues loading (but of course without the expected output that the Java process would generate). 一旦我杀了它,webserver页面就会继续加载(但当然没有Java进程会产生的预期输出)。
What I tried so far: 到目前为止我尝试了什么:
Unfortunately I can't replace the Java code with something that's under my control. 不幸的是,我不能用我控制的东西替换Java代码。 I only have the .class file to work with. 我只有.class文件可以使用。 What I haven't tried yet is to run this under Linux, so this still might be an OSX specific issue (which would surprise me). 我还没有尝试过在Linux下运行它,所以这仍然可能是OSX特定的问题(这会让我感到惊讶)。
What the hell is going on here? 这到底是怎么回事? Any and all "wild" ideas appreciated.. thanks! 任何和所有“狂野”的想法都赞赏...谢谢!
Check ALL environment from apache AND from cmd line, including the paths, UIDs etc. 从apache和cmd行检查所有环境,包括路径,UID等。
Also check what the java process does when hanging (use truss/tusc/strace -f java xxxxxxxxxxx 2>/tmp/trace.$$ ) when wrapping it from both places (apache and cmdline), then compare the results. 还要检查挂起时java进程执行的操作(使用truss / tusc / strace -f java xxxxxxxxxxx 2> / tmp / trace。$$)从两个位置(apache和cmdline)包装它,然后比较结果。
Also, when wrapping from perl, set autoflush to 1 for stdin, stdout, stderr before exec-ing java. 另外,当从perl包装时,在执行java之前将stofout,stdout,stderr的autoflush设置为1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.