Answered step by step
Verified Expert Solution
Question
1 Approved Answer
EPOKA UNIVERSITY CEN330 Parallel Programming 2021-2022 HOMEWORK 1 Deadline: 30.12.2021 PROBLEM 1 (25 pts) - Multithreaded Search in Files In this problem you are required
EPOKA UNIVERSITY CEN330 Parallel Programming 2021-2022 HOMEWORK 1 Deadline: 30.12.2021 PROBLEM 1 (25 pts) - Multithreaded Search in Files In this problem you are required to write a program named Multithreaded Search (using Java multithreading) which will search for a keyword in one or more files. The program will receive as command line arguments the keyword, the list of files and an optional argument which is -liveResults. You have to start a new thread for each file. If the option-liveResults is not provided, the program will print the total number occurrences of the keyword in each file and the total number of occurrences in all files altogether. If the option -liveResults is provided, firstly the program will print each occurrence that finds during the execution and later it will print the total number occurrences of the keyword in each file and the total number of occurrences in all files altogether. A sample execution may be using the command: java Multithreaded Search Albania sample.txt foo.txt other.dat And then some correct outputs of the program may appear like: SUMMARY: : sample.txt: 3 occurrences foo.txt: 2 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania or SUMMARY: foo.txt: 2 occurrences sample.txt: 3 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania Or SUMMARY: other.dat: 4 Occurrences sample.txt: 3 occurrences foo.txt: 2 occurrences TOTAL: 9 occurrences of keyword Albania (The order of the files in the output is not relevant, but the total must be in the last line. 1 Another sample execution may be using the command: java Multithreaded Search Albania sample.txt foo.txt other.dat -liveResults And then some correct outputs of the program may appear like: LIVE RESULTS: sample.txt: 1 occurrence at line 15 other.dat: 2 occurrences at line 13 sample.txt: 1 occurrence at line 24 foo.txt: 1 occurrence at line 18 other.dat: 1 occurrence at line 39 sample.txt: 1 occurrence at line 95 foo.txt: 1 occurrence at line 68 other.dat: 1 occurrence at line 62 SUMMARY: sample.txt: 3 occurrences foo.txt: 2 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania or LIVE RESULTS: foo.txt: 1 occurrence at line 18 sample.txt: 1 occurrence at line 15 sample.txt: 1 occurrence at line 24 other.dat: 2 occurrences at line 13 foo.txt: 1 occurrence at line 68 sample.txt: 1 occurrence at line 95 other.dat: 1 occurrence at line 39 other.dat: 1 occurrence at line 62 SUMMARY: sample.txt: 3 occurrences 3 foo.txt: 2 occurrences other. dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania (The order of the lines in the live results is not relevant, but the summary must appear after (, the live results. Also, the order of the files in the summary is not relevant, but the total must be in the last line.) 2 EPOKA UNIVERSITY CEN330 Parallel Programming 2021-2022 HOMEWORK 1 Deadline: 30.12.2021 PROBLEM 1 (25 pts) - Multithreaded Search in Files In this problem you are required to write a program named Multithreaded Search (using Java multithreading) which will search for a keyword in one or more files. The program will receive as command line arguments the keyword, the list of files and an optional argument which is -liveResults. You have to start a new thread for each file. If the option-liveResults is not provided, the program will print the total number occurrences of the keyword in each file and the total number of occurrences in all files altogether. If the option -liveResults is provided, firstly the program will print each occurrence that finds during the execution and later it will print the total number occurrences of the keyword in each file and the total number of occurrences in all files altogether. A sample execution may be using the command: java Multithreaded Search Albania sample.txt foo.txt other.dat And then some correct outputs of the program may appear like: SUMMARY: : sample.txt: 3 occurrences foo.txt: 2 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania or SUMMARY: foo.txt: 2 occurrences sample.txt: 3 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania Or SUMMARY: other.dat: 4 Occurrences sample.txt: 3 occurrences foo.txt: 2 occurrences TOTAL: 9 occurrences of keyword Albania (The order of the files in the output is not relevant, but the total must be in the last line. 1 Another sample execution may be using the command: java Multithreaded Search Albania sample.txt foo.txt other.dat -liveResults And then some correct outputs of the program may appear like: LIVE RESULTS: sample.txt: 1 occurrence at line 15 other.dat: 2 occurrences at line 13 sample.txt: 1 occurrence at line 24 foo.txt: 1 occurrence at line 18 other.dat: 1 occurrence at line 39 sample.txt: 1 occurrence at line 95 foo.txt: 1 occurrence at line 68 other.dat: 1 occurrence at line 62 SUMMARY: sample.txt: 3 occurrences foo.txt: 2 occurrences other.dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania or LIVE RESULTS: foo.txt: 1 occurrence at line 18 sample.txt: 1 occurrence at line 15 sample.txt: 1 occurrence at line 24 other.dat: 2 occurrences at line 13 foo.txt: 1 occurrence at line 68 sample.txt: 1 occurrence at line 95 other.dat: 1 occurrence at line 39 other.dat: 1 occurrence at line 62 SUMMARY: sample.txt: 3 occurrences 3 foo.txt: 2 occurrences other. dat: 4 occurrences TOTAL: 9 occurrences of keyword Albania (The order of the lines in the live results is not relevant, but the summary must appear after (, the live results. Also, the order of the files in the summary is not relevant, but the total must be in the last line.) 2
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started