Results 1 to 5 of 5
  1. #1
    cinjojose is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default Which thread do the process first if we use multithreading ?

    I have a common doubt. :confused:

    If we use two synchronized threads simultaneously for reading and writing for a database, which thread will access first.

    I mean,

    We have two synchronized threads

    Thread 1 for reading a database.
    Thread 2 for writing to the same database.

    If these two threads tries to do their process simultaneously which thread will access first the database (Read or write will happen first) ??

    How to decide it ?? :confused:


    Thanks a lot ..........

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    What do you mean by "two synchronized threads"?
    The general answer is you can't tell which one runs first.
    Certainly not without knowing what your code looks like.

  3. #3
    cinjojose is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

    Default

    r035198x,
    thanks for ur quick reply,
    I don't have much experience in multi thread programing. One interviewer asked this question to me. And i was so confused and couldn't answer for this.

    So the answer is, we can't tell which one access the DB first, the system decide it. Right ??

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Sort of, yes.

  5. #5
    cinjojose is offline Member
    Join Date
    Oct 2009
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Applet and multithreading
    By pricelessjunk in forum Threads and Synchronization
    Replies: 1
    Last Post: 08-03-2009, 09:47 PM
  2. multithreading
    By shilpa.krishna in forum New To Java
    Replies: 2
    Last Post: 06-27-2008, 04:18 PM
  3. Multithreading + Networking (desperate)
    By bluebarca in forum New To Java
    Replies: 1
    Last Post: 11-07-2007, 02:14 PM

Posting Permissions

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