Solved

can i write this in other format?

Posted on 2004-04-10
5
183 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
5 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 250 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 250 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Arrays.asList  VS  ArrayList 4 71
fibonacci ten numbers 4 45
tomcat startup error 5 100
Tagging and Merging on Branch 1 29
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

790 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