Results 1 to 7 of 7
  1. #1
    yolo is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Multiple Threads and Synchronization

    Hi Yalll!
    I have an assignment to use multiple threads and single threads to see the difference in processing time.
    But it seems like my single thread process time is faster or about the same as using multiple threads (even with the larger num of Order)
    edited th3 code. thanks for xorrecting my misunderstanding
    Last edited by yolo; 04-29-2012 at 04:30 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Multiple Threads and Synchronization

    You don't define what the Worker class is...but
    Java Code:
    Worker wor= new Worker (takesInFile, MapofOrders);
    Are you actually dividing up the work? The above line suggests that each worker is performing all the work, as opposed to splitting up the work between Threads.

  3. #3
    yolo is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Multiple Threads and Synchronization

    no each worker takes in one file to read ....
    I could mofiify it to:
    Java Code:
    for (int i = 0; i < threads.length; i++) {
    String filename = baseFileName + i + "txt;
    Worker wor= new Worker (fileName, MapofOrders);
    }
    sorry for not making it clear

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Multiple Threads and Synchronization

    How do you define 'faster'? Are you profiling with System.currentTimeMillis?

    All of these questions could be better answered if you provide an SSCCE demonstrating the two scenarios

  5. #5
    yolo is offline Member
    Join Date
    Apr 2012
    Posts
    4
    Rep Power
    0

    Default Re: Multiple Threads and Synchronization

    Results:
    For about 200 orders:
    It takes Processing time (msec): 21338 for multipleThreads
    and It take Processing time (msec): 21261 if I don't use multipleThreads

  6. #6
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Multiple Threads and Synchronization

    200 Orders == 200 Threads...yikes. You should realize that more is not necessarily better. You only have a small number of processors and each thread can only work at one time on one of those processors - 200 Threads means you have overhead of distributing the work amongst a small number of processors, requiring a lot of overhead acquiring locks and such and not necessarily resulting in a performance gain. I would recommend starting small - first splitting a list of say 200 into 2 lists of 100, and have 2 threads operate on those two lists. I would also recommend adding some println's in there so you know at runtime that you are in single or multi-thread mode.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: Multiple Threads and Synchronization

    Moved from new to Java

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Threads synchronization with wait() & notify() problem
    By Cropcircles in forum Threads and Synchronization
    Replies: 4
    Last Post: 03-25-2012, 10:44 PM
  2. One process open multiple threads on multiple CPUs
    By kfcnhl in forum Threads and Synchronization
    Replies: 2
    Last Post: 12-12-2011, 08:27 AM
  3. synchronization issue with multiple threads
    By harmeet in forum Threads and Synchronization
    Replies: 0
    Last Post: 05-01-2011, 04:01 AM
  4. Threads and Synchronization
    By ASADUN in forum Threads and Synchronization
    Replies: 4
    Last Post: 12-18-2009, 07:00 AM
  5. Odd Even number synchronization in threads
    By DukeNukem in forum Threads and Synchronization
    Replies: 1
    Last Post: 03-16-2009, 02:02 PM

Tags for this Thread

Posting Permissions

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