RTC Forums
November 23, 2024, 11:35:57 PM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Help
Login
Register
RTC Forums
>
Subscription
>
Support
>
Is RtcQuickJob.Post threadsafe ?
Pages: [
1
]
« previous
next »
Print
Author
Topic: Is RtcQuickJob.Post threadsafe ? (Read 4885 times)
HelgeLange
RTC Expired
Posts: 100
Is RtcQuickJob.Post threadsafe ?
«
on:
March 01, 2016, 03:48:46 AM »
as the title says.. if I post a new quickjob, is that threadsafe ? or do I have to make sure I post only from 1 certain thread ?
Helge
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Is RtcQuickJob.Post threadsafe ?
«
Reply #1 on:
March 01, 2016, 07:32:01 AM »
The
Post
method on the
TRtcQuickJob
component is thread-safe.
It can be used from any number of threads, at the same time.
Also, check the
Serialized
and
GUI
properties of the component. They define the behavior of the component. With
GUI=True
, all jobs will be executed serialized from the main thread. With
Serialized=True
, all jobs will be executed serialized from a background thread (using one virtual thread). With
Serialized=False
and
GUI=False
, a separate virtual thread will be created for every job posted, allowing all jobs to be running at the same time, each from a separte thread.
PS. Since using the component with GUI=False will be executing your code in the "OnExecute" event from a background thread, you have to make sure that your code is thread-safe.
Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
Posts: 100
Re: Is RtcQuickJob.Post threadsafe ?
«
Reply #2 on:
March 01, 2016, 02:33:53 PM »
Thanks for explaining it. I use it serialized = True and GUI = False, which should be then 1 thread like a queue, doing one posted job after another, therefore accessing the database stuff only from inside the one thread.
Helge
Logged
D.Tkalcec (RTC)
Administrator
Posts: 1881
Re: Is RtcQuickJob.Post threadsafe ?
«
Reply #3 on:
March 01, 2016, 03:02:48 PM »
With
Serialized=True
and
GUI=False
, execution will be serialized, which means that your jobs will be executed one-at-a-time (in the order they were added to the queue), but ... because the TRtcQuickJob component uses a
shared RTC thread pool
rather than allocating a new TThread for itself, each one of your "jobs" might actually be executed from a different thread. This should NOT be a problem, unless the components you are using (inside the "OnExecute" event) are expecting to always be used from the exact same Thread.
PS. If you are using ADO or some other Active-X components in RTC threads, because ActiveX components require "CoInitialize" to be called from every background thread which uses them, you will have to use the "
rtcActiveX
" unit somewhere in your Project. The rtcActiveX unit implements a custom initialization procedure for RTC Threads, adding one "CoInizialize" call at the start of every RTC thread.
Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
Posts: 100
Re: Is RtcQuickJob.Post threadsafe ?
«
Reply #4 on:
March 01, 2016, 06:13:36 PM »
I'm using UniDAC for database. and in one project *shameful look around* also DBX.
The database components are used outside only for init and close operations when already nothing is running anymore.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Dashboard
-----------------------------
=> General
=> 3rd-Party
=> Quick Start
-----------------------------
Subscription
-----------------------------
=> Support
Loading...