Results 1 to 7 of 7
- 04-28-2012, 08:12 PM #1
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
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.
- 04-28-2012, 08:57 PM #2
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
Re: Multiple Threads and Synchronization
You don't define what the Worker class is...but
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.Java Code:Worker wor= new Worker (takesInFile, MapofOrders);
- 04-28-2012, 09:10 PM #3
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
Re: Multiple Threads and Synchronization
no each worker takes in one file to read ....
I could mofiify it to:
sorry for not making it clearJava Code:for (int i = 0; i < threads.length; i++) { String filename = baseFileName + i + "txt; Worker wor= new Worker (fileName, MapofOrders); }
- 04-28-2012, 09:25 PM #4
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
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
- 04-28-2012, 09:36 PM #5
Member
- Join Date
- Apr 2012
- Posts
- 4
- Rep Power
- 0
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
- 04-28-2012, 10:19 PM #6
Moderator
- Join Date
- Jul 2010
- Location
- California
- Posts
- 1,608
- Rep Power
- 5
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.
- 04-28-2012, 10:25 PM #7
Similar Threads
-
Threads synchronization with wait() & notify() problem
By Cropcircles in forum Threads and SynchronizationReplies: 4Last Post: 03-25-2012, 10:44 PM -
One process open multiple threads on multiple CPUs
By kfcnhl in forum Threads and SynchronizationReplies: 2Last Post: 12-12-2011, 08:27 AM -
synchronization issue with multiple threads
By harmeet in forum Threads and SynchronizationReplies: 0Last Post: 05-01-2011, 04:01 AM -
Threads and Synchronization
By ASADUN in forum Threads and SynchronizationReplies: 4Last Post: 12-18-2009, 07:00 AM -
Odd Even number synchronization in threads
By DukeNukem in forum Threads and SynchronizationReplies: 1Last Post: 03-16-2009, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks