• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

does join method hinders performance

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic