RTC Forums
November 01, 2024, 12:10:12 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Is RtcQuickJob.Post threadsafe ?  (Read 4797 times)
HelgeLange
RTC Expired
*
Posts: 100


« 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 Smiley
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« 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


« 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


« 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


« 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  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 16 queries.