Results 1 to 10 of 10

Thread: Threads Best Practice

  1. #1
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default Threads Best Practice

    Hi, all delphi fans , me again.

    Which is best when working with threads?
    1: put all the code in the body of the thread
    2:have the thread make function calls on itself MyThead->some_function

    Option 2 presumes that we have sub classed the TThread class

    As it stands functions are still the best way to illiminate code complexity , but do we want to do that?
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  2. #2
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    It boils down to the purpose of the thread that will determine what method is best used. The purpose of the thread would decide whether or not to call its code in the execute method or in procedures of the class.

    For example, a thread that is created every 5 minutes to check file I/O status can be achieved by just executing that code in the Execute method of the thread. Now, if you're interacting with the main thread and need to update visual controls, you will have to create a descendant and use the Synchronize method which will require a procedure of the class.

    The purpose of the thread dictates how you go about designing it.

  3. #3
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default

    My thoughts were more along the lines of performance/accuracy when working with databases and having to execute multiple queries against one of more data-stores. at present i am working on a archive system (don't ask why)
    that has to check for the existence of records coming from the src and going to the destination. If there are records in the destination coming in i would have to log the records to another database and then delete from where they are now then import sounds..mixed i know...

    this has me wondering about how the thread will person if it has to make too many procedure/function calls or should it simple write the entire thing in the execute statment
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  4. #4
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Does any of the databases in question support triggers?

  5. #5
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default

    Sure , the servers are MSSQL2000. What did you have in mind?
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  6. #6
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    The checking of existing records and saving them before overwriting is a candidate for an audit trails setup. Setup triggers to save that data to either shadow tables or another database dump with a timestamp, process id and possibly a user id; then overwrite that data. This would move that function to the database and save you the headache of having to code threads for it.

    Databases are very efficient at auditing themselves. Now as far as batch updates are concerned, those can be done right in the Execute method of the thread, so as long as you are not using a dataset connected to a widget.

  7. #7
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default

    The checking of existing records and saving them before overwriting is a candidate for an audit trails setup

    Can you provide a sample of the above or explain it some more...how will i trigger the the (trigger) to make the copy of a record that i choose?
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  8. #8
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Here is a trigger function (PostgreSQL) that records changes made to one of the tables used in an app I'm developing. It monitors changes in benefits to employees.

    Code:
    CREATE or REPLACE FUNCTION "audit"."audit_public_allowances_func"()
    RETURNS "pg_catalog"."trigger" AS 
    $BODY$
    BEGIN
    				INSERT INTO audit.public_allowances_history
    					SELECT NOW(), TG_OP, OLD.*;
    				RETURN NULL;
    			END;
    $BODY$
    LANGUAGE 'plpgsql' VOLATILE;
    Whatever change is made to this table is first recorded in its audit counterpart along the with operation (INSERT, UPDATE, DELETE) and the value being changed and the time changed. That way I have a complete history of all values that was ever recorded in my table and when those values were changed.

  9. #9
    Join Date
    Sep 2004
    Posts
    281
    Rep Power
    0

    Default

    Ho hell my brain must be frozen. off course triggers...............lol......sigh. thanks man.......i forgot about those..........will do ...........
    Anything or Anyone that fails to grow will eventually die. {AI}
    -------------------------------------------------
    Tomorrow is the future!
    Today Is the Tomorrow you made Yesterday!{AI}

  10. #10
    Join Date
    Mar 2003
    Posts
    492
    Rep Power
    0

    Default

    Good, so now you can use your thread to populate the tables. Let databases monitor themselves.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •