First Crack at Multithreaded Programming

  • Thread starter Thread starter peterpiper
  • Start date Start date
  • Tags Tags
    Crack Programming
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
peterpiper
Messages
12
Reaction score
0

Homework Statement



Create a multithreaded program (Java) that finds a word in a text file and reports the lines one which the word appeared. Word lines should be reported in the order in which they appear.

Homework Equations





The Attempt at a Solution



I know that I can just start up a bunch of threads to run over different parts of the text file,, but that gives the potential that the lines are going to be returned in all sorts of messy errors. Any suggestions or help materials that could help me preserve the order of the returns while also managing to increase speed over the single-threaded program?
 
Physics news on Phys.org
You can give each thread a small part of the text, so all threads run over "some fraction of the first n% of the text" in parallel. Collect the results, sort them*, print them, continue with the next n% of the text (can be done in parallel to the sorting of course).

*trivial with a good line distribution