如何在 PrintStackTrace 后保持 CFEXECUTE 不挂起

时间:2023-01-15
本文介绍了如何在 PrintStackTrace 后保持 CFEXECUTE 不挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ColdFusion MX7 对一些 Java 6 代码执行 CFEXECUTE.

I'm using ColdFusion MX7 to perform a CFEXECUTE on some Java 6 code.

不幸的是,由于 CF7 在 JDK 6 下无法运行,我必须这样做.

Unfortunately, since CF7 does not work under JDK 6 I must do it this way.

我的问题是,当 Java 代码中发生异常时,如果我在异常上调用 printStackTrace,CFEXECUTE 命令会挂起.ColdFusion 最终超时,但 Java 进程继续在后台挂起.

My problem is that when an exception happens in the Java code if I call a printStackTrace on the exception the CFEXECUTE command hangs. ColdFusion eventually times out but the Java process continues to hang in the background.

我猜有一些阻塞正在发生,但我似乎无法弄清楚原因.

I'm guessing there is some blocking going on but I can't seem to figure out why.

如果我不执行 printStackTrace 则一切正常.

If I don't do a printStackTrace then everything works fine.

异常是使用 JAXWS 从 Oracle 信息权限管理 wsdl 生成的 WebService 异常.

The exceptions are WebService exceptions generated with JAXWS from the Oracle Information Rights Management wsdl.

编辑

我注意到我可以使用文件 PrintStream 作为参数调用 printStackTrace 并且它工作正常.所以,看起来错误流有问题.

I noticed that I am able to call the printStackTrace with a file PrintStream as a parameter and it works fine. So, it looks like the error stream is having troubles.

这里是 Java 代码:

Here is the Java Code:

public void Execute(){
    AdminUtils AU = AdminUtils.GetInstance();

    AccountServicesPort AA = AU.GetAccountServicesPort(); 

    LicenseServerRef LicSerRef = AU.GetLicenseServerRef();

    User UserToSave = new User();
    UserToSave.setUserName(UserName);
    UserToSave.setFirstName(FirstName);
    UserToSave.setLastName(LastName);
    UserToSave.setEmailAddress(EmailAddress);
    UserToSave.setServer(LicSerRef);

    try{
        AU.LogMessage("Change User: " + UserName + " " + FirstName + " " + LastName + " " + EmailAddress);
        AA.saveChangesToUser(UserToSave);
    }catch(Exception e){
        e.printStackTrace();
    }
}

这是 ColdFusion 调用:

Here is the ColdFusion call:

<!--- Update the IRM User. --->
<CFEXECUTE name="c:Program FilesJavajdk1.6.0_14injavaw.exe"
           arguments="-cp C:CFusionMX7ExternalsIRM.jar;C:CFusionMX7ExternalsConfig IRMWebServices.UpdateUser #LoginID# #NewFname# #NewLname#"
           timeout="15" 
           variable="OUTPUT">
</CFEXECUTE>

推荐答案

是的,e.printStackTrace(); 写入 stderr(标准错误流).由于 cfexecute 不捕获标准错误,这可能是导致 cfexecute 挂起的原因.有一个补丁可以修复 CF8 中的这种行为.

Yes, e.printStackTrace(); writes to stderr (standard error stream). Since cfexecute does not capture stderr, that is probably what is causing cfexecute to hang. There was a patch to fix this behavior in CF8.

由于您使用的是 7,请尝试 Ben Forta 的提示:

Since you are using 7, try Ben Forta's tips about:

  • 将标准错误重定向到标准输出:几个问题
  • 运行命令并在完成后终止的标志:使用 CFEXECUTE 执行命令行实用程序

同时使用 /c2>&1 应该可以解决挂起问题.

Using both /c and 2>&1 should get rid of the hanging problem.

更新:添加示例

ColdFusion 代码:

<cftry>  
    <cfset argString = '/c "C:Program FilesJavajdk1.6.0_13injava.exe" -cp c:myJar.jar TestStdErr 2>&1'  >  
    <cfexecute name="c:windowssystem32cmd.exe" 
        arguments="#argString#"    
        outputFile="c:cfexcuteResults.log" 
        timeout="5" />  
    <cfcatch>  
       <cfdump var="#cfcatch#">  
    </cfcatch>  
</cftry>  

Java 类:

public class TestStdErr {
    public static void main(String[] args) {
        try {
            // cause a divide by zero exception 
            int a = 0;
            int b = 2 /a;
         }
         catch(Exception e){
            e.printStackTrace();
        }
    }
}

这篇关于如何在 PrintStackTrace 后保持 CFEXECUTE 不挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:ColdFusion 没有捕捉到 NoClassDefFoundError 下一篇:如何在 Coldfusion 中使用 java 文件

相关文章

最新文章