wood burning stoves 2.0*
The moose likes Threads and Synchronization and the fly likes Does performance improves with multithreading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Does performance improves with multithreading" Watch "Does performance improves with multithreading" New topic
Author

Does performance improves with multithreading

varun prakash
Greenhorn

Joined: Oct 12, 2006
Posts: 17
Hi All,
I've a doubt regarding performance improvement in multithreading. Lets assume I have to execute 100 tasks(Each one will take equal time to execute) and there is no database dependence or there is no need to wait for anything, for each of these tasks.

In this case,lets assume I've 10 threads which are executing these 100 tasks.what performance improvement can I get by using multithreading, instead of using single threading and executing my tasks one by one.

Because as far as I know, even in case of multithreading only one thread can execute at a time (My machine has a single processor). so even in multithreading, all threads will follow some kind of time slicing mechanisms. So I feel that the total time to execuete all the 100 tasks by using Single threading or multithreading is the same. Am I correct (or) I didn't understand something about multithreading regarding performance improvement? Please reply.

Thanks in Advance,
VarunJ


SCJP - 98%<br />SCWCD - 89%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41574
    
  54
It sounds like there would be no speedup by using multiple threads, and possible a slowdown due to the overhead of context switching. If all the work to be done is just computation (no disk or network I/O), then you're right that there isn't any scope for parallelism.


Ping & DNS - my free Android networking tools app
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

The work done is the same, single threaded or multi-threaded. Except that multithreaded has some overhead, so it uses a bit more.

If you are CPU bound and on a single CPU, multi-threading will be slower by the overhead.

If you are IO bound in any way, it may be faster to multi-thread. IO can mean anything here, from waiting for a user to click on a form, to reading a disk or talking to a Sql database on another computer.

Today, quad processor chips are common. Multi-threading can give you nearly a 4 to one improvement in execution time (altho 3 to one is more likely)

Soon, Intel will have 8, 16, and 32 processor chips.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Does performance improves with multithreading