aspose file tools*
The moose likes Threads and Synchronization and the fly likes sorting in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "sorting in thread" Watch "sorting in thread" New topic
Author

sorting in thread

Sara Brown
Ranch Hand

Joined: Feb 22, 2012
Posts: 55
can we do sorting using threads that consume less memory and faster than the old version(non-thread)?


how to make sure the thread programming gonna help us running the program a lot faster n consume less memory?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12778
    
    5
asparagus white wrote:can we do sorting using threads that consume less memory and faster than the old version(non-thread)?


how to make sure the thread programming gonna help us running the program a lot faster n consume less memory?


Everything that happens in a Java program is done by a Thread so "non-thread" makes no sense.

I have used multiple Threads in a program that read files, parsed and sorted and wrote files where the sort thread could work while the IO threads were waiting for reading or writing resulting in very high CPU utililization. Needless to say this was a very special case - so the answer to your question is "it depends."

Bill
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

asparagus white wrote:can we do sorting using threads that consume less memory and faster than the old version(non-thread)?


Some sorting algorithms lend themselves to multithreading better than others. This is not really a Java topic. It's a general CS topic. Usually, however, increasing speed also means increasing memory usage.

how to make sure the thread programming gonna help us running the program a lot faster n consume less memory?


You can't guarantee that a multithreaded approach will run faster than a single-threaded one. But in general, for CPU-bound tasks (which sorting is, if the set to be sorted isn't huge), setting the number of threads equal to the number of CPUs or cores will give you the best performance.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sorting in thread