Thread management
Problem Statement:
Scripts are executed within a language specific script runtime (also called
script engine). We need to define the features of this runtime and the contract
between the runtime and the scripts it runs with regard to threading.
Requirements:
- define the thread management model that script runtimes should
use
Use Cases:
How could scripts be started?
- by running a script from the StarOffice Script UI
- by running a script from an IDE
- when an application or document event occurs to which a script is
bound
- by a script invoking another script
- by a script precipitating an event to which a script is bound
- by a script invoking itself
- programmatically via the StarOffice API
Scripts can run in different ways:
- scripts that run to completion without interruption
- scripts that require user input to continue
- scripts that run in the background at specific intervals
- scripts that run continuously in the background
Analysis:
What is the concurrency model used by the script manager?
1. Do nothing to ensure thread safety. Allow any script to be run at any
time in any context.
2. Use the same model StarOffice currently uses for StarBasic scripts, ie.
allow only one script to run at a time.
3. Implement a threading model that allows the user to run one script per application/document context. This is similar to COM's Single Threaded Apartment (STA) Model where the application/document context would be the apartment in which only one script would be allowed to execute at a time. Before executing a script, the script engine would need to obtain a lock for the particular application/document context which it would release when the script has completed.
Suggested solution: 3
If we support concurrency via the STA, the same script could be run simultaneously
in many contexts. What about scripts which are not thread safe?
1. Do nothing, script developers have to synchronize their own scripts
2. Use something like the SingleThreadModel interface of the Java servlet API, so that the developer can specify whether their script is thread safe or not in the deployment descriptor. The script manager ensures that SingleThreadModel scripts are not executed concurrently.
Suggested solution: 2