The Pooling
takes advantage of the WorkspaceManager being a COM singleton object
(which means that only a single instance of the WorkspaceManager component
is created in any given process). In other words, every time a call
to CoCreateInstance (which is what Visual Basic's CreateObject and
dim x as New object use) is made in the same process, the same WorkspaceManager
object is returned. Therefore, the same pools are available to all
callers in the same process.
To create and use a
pool of workspaces, perform the following steps:
-
Create the Pool (use
CreatePoolByServer or CreatePoolByLogicalName). This step needs to
be performed only once, usually when the application is started. You
will get an error if you try to create a pool using a logical name
that has already been used in a pool.
-
Get a PooledWorkspace
object from the pool (use GetPooledWorkspace). The PooledWorkspace
is really just a wrapper around the SAS.Workspace object that is being
pooled. This wrapper is necessary to notify the pooling code when
you are finished using the pooled workspace. In pooling, you will
want to keep a reference to the pooled workspace for as long as you
keep a reference to the workspace.
-
Use the workspace. For
example, you might run a stored process and retrieve the output from
SAS.
-
Release the workspace
and the PooledWorkspace. In Visual Basic, you can release these objects
by either letting them go out of scope or by calling:
set obPooledWorkspace = Nothing
The pool will continue
to run until either your process exits or you call Shutdown() on each
pool. Simply releasing your reference to the WorkspaceManager is not
enough.
In an ASP application,
there are two ways the pool can be created: in the Application_OnStart
callback in the global.asa, or in the code that calls to get the PooledWorkspace.
The following code is written in Visual Basic; some changes are needed
to write it in VBScript.
Once a pool is running,
methods and properties are available on the SASWorkspaceManager.WorkspacePool
object to look at statistics about the pool to and shut down the pool.