*
The moose likes Threads and Synchronization and the fly likes does join method hinders performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "does join method hinders performance" Watch "does join method hinders performance" New topic
Author

does join method hinders performance

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
ArrayList processorsList = new ArrayList( no_intfiles.intValue() );
for ( int x = 0; x <no_intfiles.intValue(); x++ ) {
System.out.println(" There is a file(Value of x)" + x);
System.out.println(" :File Name is: " + no_files[x].getName());
Processor processor = new Processor (no_files[x].getName());
processorsList .add( processor);
Processor.start();
}

for ( int _idx = 0; _idx < processorsList .size(); _idx++ ) {
( ( Processor ) processorsList .get( _idx ) ).join();
}

I parse and process xml files and create text files. I call processor class for every xml file. I use join method. If I process every file individually, 4 files take 20 minutes to process(320 mb size all files).
But If i process all 4 files together creating multiple processor. They take around the same time.
Threads are not making this faster. Is it because of join method.
I am not sure what join() method does.
Does anyone give me ideas to make it efficient and faster.


Bhasker Reddy
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Running parallel tasks will only help if individual threads yield the CPU. If a thread is doing very CPU intensive computations then it won't let any other threads get much done. But if a thread does a lot of relatively slow blocking operations like disk IO over a network other threads can sneak in while it is waiting. I have a program that downloads files over the Internet ... when I run five threads they all run as fast as one by itself. I figure the remote server's bandwidth is the bottleneck.

Can we analyze your XML processing tasks? Maybe run a single thread and see how CPU usage looks. If it's running near 100% then parallel tasks won't have much chance. If it's much lower then parallel tasks might work to your advantage. Try two or three threads and see how CPU compares. Lettuce know what you find!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

To strengthen what Stan said a bit: on a single-processor machine, running four compute-intensive tasks in four threads will likely take longer then running them sequentially. You can only expect processing in parallel to be faster if either (a) you're running on a multi-CPU computer, or (b) each individual thread is I/O bound, rather than CPU bound. Your description sounds perfectly unsurprising if the tasks are mainly CPU-bound and you're on a single-processor machine.


[Jess in Action][AskingGoodQuestions]
 
Consider Paul's rocket mass heater.
 
subject: does join method hinders performance
 
Similar Threads
arraylist
recursive function usage in JSP
creating a tree in JSP
file parsing in drive (how many drives )
View JPG Image from Servlet File