Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

java - How do I keep CFEXECUTE from hanging after a 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 FilesJavajdk1.6.0_14injavaw.exe"
           arguments="-cp C:CFusionMX7ExternalsIRM.jar;C:CFusionMX7ExternalsConfig IRMWebServices.UpdateUser #LoginID# #NewFname# #NewLname#"
           timeout="15" 
           variable="OUTPUT">
</CFEXECUTE>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...