?
Solved

can i write this in other format?

Posted on 2004-04-10
5
Medium Priority
?
195 Views
Last Modified: 2010-03-31
thx..

here is the code?
can i write the function in void process(..) in other format?

----------------------
class Server
{

void Do(String w) { . . . }

void Process(final String line)
{ Thread t = new Thread() { public void run() { Do(line);
}
};
t.start();
}
}

Server (InputStream instream) { BufferedReader in = new BufferedReader(new InputStreamReader(instream));
String line;
try { while ((line = in.readLine()) != null) { Process(line);
}
}catch (IOException e) { }
}
}
0
Comment
Question by:tom_mk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 1000 total points
ID: 10800004
You can do what you're thinking, but I would strongly recommend against as you would be starting a thread per line in a file. This is bad as threads are expensive to create, and switch between.
0
 

Author Comment

by:tom_mk
ID: 10800031
example?
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 1000 total points
ID: 10800203
If you think that the processing of those data must be done parallel, the only reason could be
that you're on a system with, say, 16 CPU's. That makes sense.
However, if the # of lines in the file is much greater than 16, you will waste a lot of time with all those
threads.

I had to write something similar, well, you can create a collection (synchronised like Vector)
where threads may pick one line by one line to do their work.
Then you start as many threads as makes sense (16 in the case above).

Now, every thread can loop: pick a line, process it, pick a line .... until exhausted.
That will be very efficient.

In my case I had to start a thread on every single data set, but then I linked the threads also in a vector.
Every thread started looked in that vector to see if its rank was higher than the # of CPU's.
If so it slept for a while; this way no more threads were running than CPU's available,
still all datasets had a thread and so a run-status that could be retrieved.

You may choose.

;JOOP!
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month8 days, 15 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question