多线程对oracle数据库操作,内存居高不下(100分)

W

wksdgy

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Umanger_thread;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, DB, Grids, DBGrids,StrUtils, ActiveX,
ComCtrls, OoMisc, AdPort,Registry,Buttons,DBCtrls,ImgList, Mask, CRGrid,MsgExch,
Ora, Tel_DM,
OraSmart, MemDS, DBAccess,IdUDPServer,Ubwfy_tread,OraProvider,DBClient,Provider;
type
Tmanger_thread = class(TThread)
private
{ Private declarations }
my_memo1:tmemo;
local_OraSession: TOraSession;
cur_bw_dataset:TOraQuery;
protected
procedure resolve_data;
procedure create_orasession;
procedure Execute;
override;
public
constructor create(memo1:tmemo);
destructor Destroy;
override;
end;
var
manger_thread_session: Tmanger_thread;
implementation
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure Tmanger_thread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ Tmanger_thread }
constructor Tmanger_thread.create(memo1: tmemo);
begin
my_memo1:= memo1;
create_orasession;
freeonterminate:=true;
inherited Create(False);
end;

procedure Tmanger_thread.create_orasession;
begin
CoInitialize(nil);
local_OraSession:=TOraSession.Create(nil);
local_OraSession.ConnectString:='bwxx/bwxx@127.0.0.1:1521:bwxx';
local_OraSession.Options.Net:=true;
local_OraSession.ConnectPrompt:=false;
local_OraSession.AutoCommit:=true;
local_OraSession.Connected := false;
cur_bw_dataset:=TOraQuery.Create(nil);
cur_bw_dataset.Session:=local_OraSession;
end;


destructor Tmanger_thread.Destroy;
begin
try
freeandnil(cur_bw_dataset);
local_OraSession.Connected:=false;
freeandnil(local_OraSession);
CoUnInitialize;
inherited;
except
end;
end;

procedure Tmanger_thread.Execute;
var
str1,xh,m_ysbw:string;
mysql:string;
begin
try
while truedo
begin
if (cur_bw_dataset.Eof) then
begin
cur_bw_dataset.Close;
cur_bw_dataset.SQL.Clear;
mysql:='select myid,mybwxx from bwxx where rownum<30 order by myid';
cur_bw_dataset.SQL.Add(mysql) ;
cur_bw_dataset.Open;
end ;
cur_bw_dataset.First;
while not cur_bw_dataset.Eofdo
begin
m_ysbw:= cur_bw_dataset.fieldbyname('mybwxx').AsString;
xh:= cur_bw_dataset.fieldbyname('myid').AsString;
if (cur_tread_num<max_tread) then
begin
if manager_list.IndexOf(xh)<0 then
begin
bwfy_session:=TBWFY_TREAD.create(m_ysbw,my_memo1,xh);
end;
cur_bw_dataset.Next;
end;
sleep(1);
application.ProcessMessages;
end;
sleep(1000);
application.ProcessMessages;
end;

except
end;

end;

end.
 
内存居高不下是不是cur_bw_dataset打开的数据记录过多啊、。
 
有记录的时候才取29条记录,但实际上不可能取29条记录,是不是TBWFY_TREAD这个线程造成的,这个TBWFY_TREAD线程可能会同时往一个表中写数据,但问题是后台是oracle数据库,数据库本身会自动处理并发操作,内存居高不下的问题已经困扰我很多天了,该释放的都释放了,但还是解决不了问题
 
while truedo
[:)]
 
while truedo
循环中有sleep和application.processmessage语句,应该不会是它造成内存居高不下,我怀疑是不是多个TBWFY_TREAD线程往一个表中写数据产生报错,导致代码创建的控件无法释放
 
顶部