1

オブジェクトのプール (私の場合はスレッド クラス) を作成するために、Spring の IObjectPool をコードに適用したいと考えています。春のプールに関する例やドキュメントはありますか?

それは次のようなものです:

TMyClass = class(TThread)
public
    constructor Create;
    procedure Execute; override;
end;

別のクラス:

uses
    ....
    Spring.Container,
    Spring.Container.Pool,
    Spring.Container.Core,
    Spring.Container.ComponentActivator,
    Spring.Services,
    ....;

TOtherClass = class
private
    FPool: IObjectPool;
    FActivator: IComponentActivator;
    ....
end;

implementation

constructor TOtherClass.Create;
begin
    FActivator := ServiceLocator.GetService<IComponentActivator>;
    FPool := TSimpleObjectPool.Create(FActivator, 5 , 10);
    FPool.Initialize(nil);
end;

procedure TOtherClass.AProcedure;
var
    task: TMyTask;
begin
    ...
    task := FPool.GetInstance(nil);
    ...
end;

XE6を使用しています。

よろしく。

4

0 に答える 0