Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 11 total
Thread Question on Threads with EDB
Sat, Jan 12 2013 9:33 PMPermanent Link

IQA

Hi Guys,

I have a client / server app running EDB.

The server app has 2 things happening.

A. It uses the 'ServerEngineServerProcedure' (called from the client
program) and then the server program runs a function that uses
TXMLDocument and also INSERTS some records into a database.

B. Also the Server program has a timer every 5 minutes which will run
the exact same function in a thread that uses TXMLDocument and also
INSERTS some records into a database.

Obviously when (A.) runs the ServerEngineServerProcedure appears to use
it's own thread created by EDB automatically. (I came to that conclusion
as I needed to call Coinitialize / CoUninitialize for the TXMLDocument
to work.

When (B.) runs I will be creating my own thread.

Therefore - should I be adding a TEDBSession component on the server
program, called say ThreadSession and have the function always use this
session in both circumstances?

There will only ever be ONE thread running at any one time, but I just
want to clarify that's what I should do?

I hope that made sense,

Cheers,

Phil.
Sun, Jan 13 2013 4:46 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Phil

The rules on threads are full isolation so yes create your own session / database / tables / queries in the thread.

Roy Lambert [Team Elevate]
Mon, Jan 14 2013 9:14 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Phil,

<< Therefore - should I be adding a TEDBSession component on the server
program, called say ThreadSession and have the function always use this
session in both circumstances? >>

As Roy indicated, you'll need a separate session for both the server
procedure and the timer.  What I would do is just instantiate the session,
database, etc. components in the function itself, make sure they are
uniquely named, and then be sure to destroy them before the function exits.

If you have any other questions, please let me know.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Jan 14 2013 5:50 PMPermanent Link

IQA

Thanks Tim,

My initial thoughts where, having all the session / database etc created
and destroyed in the function would be a simpler way to handle it...

But in reality the function grabs XML and then depending on what it
contains calls another function that uses a TRANSACTION to write data to
a few tables.

Do you have any thoughts?

Thanks again,

Phil.


 15/01/2013 1:14 AM, Tim Young [Elevate Software] wrote:
> Phil,
>
> << Therefore - should I be adding a TEDBSession component on the server
> program, called say ThreadSession and have the function always use this
> session in both circumstances? >>
>
> As Roy indicated, you'll need a separate session for both the server
> procedure and the timer.  What I would do is just instantiate the
> session, database, etc. components in the function itself, make sure
> they are uniquely named, and then be sure to destroy them before the
> function exits.
>
> If you have any other questions, please let me know.
>
> Tim Young
> Elevate Software
> www.elevatesoft.com
Mon, Jan 14 2013 6:53 PMPermanent Link

IQA

<<
Thanks Tim,

My initial thoughts where, having all the session / database etc created
and destroyed in the function would be a simpler way to handle it...

But in reality the function grabs XML and then depending on what it
contains calls another function that uses a TRANSACTION to write data to
a few tables.
>
Do you have any thoughts?

Thanks again,

Phil.
>>


Just in addition... The TIMER is running a BMThread component to handle
the thread and I can easily grab it's 'ThreadID' to uniquely name a
session... Is there a way to grab the ThreadID of the 'server procedure'
? I'm thinking probably not, so I'd have to incorporate the TEDBSession*
__fastcall GetNewSession() example from the manual.

Does that sound right?

Tue, Jan 15 2013 5:09 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Phil

>My initial thoughts where, having all the session / database etc created
>and destroyed in the function would be a simpler way to handle it...
>
>But in reality the function grabs XML and then depending on what it
>contains calls another function that uses a TRANSACTION to write data to
>a few tables.
>
>Do you have any thoughts?

First point is that as things stand you MUST maintain isolation otherwise you risk corruption.

Can the second function be be called from several places and simultaneously? Several places but NOT simultaneously? Several places and several times sequentially within the calling function?

Depending on the answer to that I'd look at the calling functions, set up the various bits and pieces in those calling functions and pass as parameters to the called function.

Wether or not its using a transaction isn't really relevant (unless Tim tells me otherwise Smiley but isolation is.

Roy Lambert [Team Elevate]
Tue, Jan 15 2013 6:39 AMPermanent Link

IQA

<<
First point is that as things stand you MUST maintain isolation
otherwise you risk corruption.
>>

Yep, understood.

<<
Can the second function be be called from several places and
simultaneously? Several places but NOT simultaneously? Several places
and several times sequentially within the calling function?
>>

The second function (infact there's a number of them called from the
main function) but they are all ONLY called via this main function and
no where else in the program.
I have 2 main functions running in a thread. One is on the timer so that
ONLY ever gets run by the server program every 5 minutes and wont ever
be run simultaneously.
The other one is called from the ServerProcedure via any client programs
logged in, but only on the rare occasion they open up a particular
screen which is rarely used (say once a month maximum) and as that
screen is opened up the client calls the ServerProcedure which runs a
function that UPDATES a few records before showing. (takes like 1 seconds).

<<
Depending on the answer to that I'd look at the calling functions, set
up the various bits and pieces in those calling functions and pass as
parameters to the called function.
>>

Currently what I've done is setup the TEBSession / TEDBDatabase in the
function using a unique ID / threadID for the SessionName, then passing
the *TEDBSession / *TEDBDatabase when I call the other functions. Those
other functions then use those to set the SessionName / DatabaseName of
any TEDBQuery / TEDBScript etc.

<<
Wether or not its using a transaction isn't really relevant (unless Tim
tells me otherwise Smiley but isolation is.
>>

Cool, appreciate that comment Roy.

Tue, Jan 15 2013 7:27 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Phil


>Currently what I've done is setup the TEBSession / TEDBDatabase in the
>function using a unique ID / threadID for the SessionName, then passing
>the *TEDBSession / *TEDBDatabase when I call the other functions. Those
>other functions then use those to set the SessionName / DatabaseName of
>any TEDBQuery / TEDBScript etc.

That's pretty much what I'd do. So unless rebuked by a higher authority you look good to go.

Roy Lambert [Team Elevate]
Tue, Jan 15 2013 11:32 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Phil,

<< Just in addition... The TIMER is running a BMThread component to handle
the thread and I can easily grab it's 'ThreadID' to uniquely name a
session... Is there a way to grab the ThreadID of the 'server procedure' ?
>>

Sure, just use:

Windows.GetCurrentThreadID

works fine under all native code scenarios.

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Jan 15 2013 5:25 PMPermanent Link

IQA

<<
Sure, just use:
Windows.GetCurrentThreadID
works fine under all native code scenarios.
>>

Thanks Tim, that's useful.
Page 1 of 2Next Page »
Jump to Page:  1 2
Image