如何在PrintStackTrace后保持CFEXECUTE挂起 [英] How do I keep CFEXECUTE from hanging after a PrintStackTrace

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

问题描述

我使用ColdFusion MX7对某些Java 6代码执行CFEXECUTE。



不幸的是,因为CF7不能在JDK 6下工作,所以我必须这样做。



当在异常时调用 printStackTrace 时,Java代码中发生异常时,CFEXECUTE命令挂起。 ColdFusion最终超时,但Java进程在后台继续挂起。



我猜想有一些阻塞,但我似乎不明白为什么。



如果我不做 printStackTrace ,那么一切都很好。



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



EDIT



我注意到我可以使用文件 PrintStream printStackTrace >作为参数,它工作正常。



这里是Java代码:

  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调用:

 <!---更新IRM用户。 ---> 
< CFEXECUTE name =c:\Program Files\Java\jdk1.6.0_14\bin\javaw.exe
arguments = - cp C:\CFusionMX7\ Externals\IRM.jar; C:\CFusionMX7\Externals\Config IRMWebServices.UpdateUser#LoginID##NewFname##NewLname#
timeout =15
variable =OUTPUT> ;
< / CFEXECUTE>


解决方案

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



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





使用 / c 2>& 1



更新:添加示例 / em>

 < cftry> 
< cfset argString ='/ cC:\Program Files\Java\jdk1.6.0_13\bin\java.exe-cp c:\myJar.jar TestStdErr 2& ; 1'>
< cfexecute name =c:\windows\system32\cmd.exe
arguments =#argString#
outputFile =c:\cfexcuteResults.log
timeout =5/>
< cfcatch>
< cfdump var =#cfcatch#>
< / cfcatch>
< / cftry>

Java类:


$ b b

  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();
}
}
}


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

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

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.

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

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

EDIT

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.

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();
    }
}

Here is the ColdFusion call:

<!--- Update the IRM User. --->
<CFEXECUTE name="c:\Program Files\Java\jdk1.6.0_14\bin\javaw.exe"
           arguments="-cp C:\CFusionMX7\Externals\IRM.jar;C:\CFusionMX7\Externals\Config IRMWebServices.UpdateUser #LoginID# #NewFname# #NewLname#"
           timeout="15" 
           variable="OUTPUT">
</CFEXECUTE>

解决方案

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.

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

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

Update: Added Example

ColdFusion Code:

<cftry>  
    <cfset argString = '/c "C:\Program Files\Java\jdk1.6.0_13\bin\java.exe" -cp c:\myJar.jar TestStdErr 2>&1'  >  
    <cfexecute name="c:\windows\system32\cmd.exe" 
        arguments="#argString#"    
        outputFile="c:\cfexcuteResults.log" 
        timeout="5" />  
    <cfcatch>  
       <cfdump var="#cfcatch#">  
    </cfcatch>  
</cftry>  

Java Class:

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挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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