[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

can i write this in other format?

Posted on 2004-04-10
5
Medium Priority
?
197 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

656 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