Uli,

On 28.02.2011 14:55, [email protected] wrote:
> When I run a Rexx script through BSF4ooRexx, it seems that streams that
> are opened in a script are not closed when the Rexx interpreter is
> finished executing the script.
>
> This code demonstrates the problem:
>
> import org.apache.bsf.*;
> public class BSFTestFileHandle {
>         public static void main(final String[] args) throws Exception {
>                 BSFManager bm = new BSFManager();
>                 testRunScript(bm);
>                 testRunScript(bm);
>         }
>
>         private static void testRunScript(final BSFManager bm) throws
> BSFException {
>                 System.out.print("The result of 'SAY LINES('TEST.TXT')'
> should be >0, but is ");
>                 BSFEngine engine = bm.loadScriptingEngine("rexx");
>                 engine.exec("test.rexx", -1, -1, "SAY LINES('TEST.TXT')");
>         }
> }
>
> The test code runs 2 times a Rexx script that opens a file (assuming a
> non-empty file called 'TEXT.TXT' exists in the current directory).
> The first time it succeeds, the second time it fails.
>
> Expected output:
> The result of 'SAY LINES('TEST.TXT')' should be >0, but is 1
> The result of 'SAY LINES('TEST.TXT')' should be >0, but is 1
>
> Actual output:
> The result of 'SAY LINES('TEST.TXT')' should be >0, but is 1
> The result of 'SAY LINES('TEST.TXT')' should be >0, but is 0
>   
You use one interpreter instance for running the Rexx code. As you are
not explicitly closing the files after the lines()-BIF you become
dependent upon the ooRexx garbage collector to be triggered in order to
close the stream of the first activation implicitly. As BSF4ooRexx is
geared towards dispatching Rexx scripts as quickly as possible, it is
likely that the ooRexx garbage collector has not been triggered yet,
such that the open stream in activation 1 is causing the access to this
file in activation 2 to not be successful.

Solution: explicitly close the streams, if you do not need them anymore,
e.g. with

   call stream 'TEXT.TXT', "C", "Close"

(Side note: each instance of BSFManager actually creates its own Rexx
interpreter instance.)

> Running the same script from the command line works as expected (i.e.
> running the following twice on the command line prints '1' twice, as
> expected): rexx -E "SAY LINES('TEST.TXT')")
>   
This is not the same scenario! In this case a Rexx interpreter is
created, runs the Rexx program and closes down fully. This is repeated
twice. The second Rexx program runs only after the first Rexx program
has been fully shut down in the process.

> I think there should be a way to have the interpreter shutting down and
> thus its held resources being released, either programmatically or for
> example in RexxEngine.terminate() and/or RexxEngine.exec() (after
> execution of the script).
>   
This is not under the control of BSF4ooRexx, unfortunately. 

What you see are the dynamics of ooRexx, where in one interpreter
instance there may be multiple Rexx programs running (does not matter if
in parallel or one Rexx program after the other in sequential order).
Maybe in your case triggering the ooRexx garbage collector explicitly
may solve the problem, if the Rexx interpreter instance gets terminated.

HTH,

---rony






------------------------------------------------------------------------------
What You Don't Know About Data Connectivity CAN Hurt You
This paper provides an overview of data connectivity, details
its effect on application quality, and explores various alternative
solutions. http://p.sf.net/sfu/progress-d2d
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to