Sample Exercises For The Lab Exam
Sample Exercises For The Lab Exam
Exercise 1: Write a multi-thread java application that performs the following two tasks
concurrently:
Hint: use just one task class to handle the two threads
Exercise 2: Write a multi-thread java application that performs the following three tasks
concurrently:
Hint: use two task classes that handle the three threads. Note that the first 3 multiples of 6 are 6,
12 and 18.
Exercise 3: Assume you have two files, say file1.txt and file2.txt inside your java project folder.
Assume also that the file1.txt file contains the text “hello” whereas the file2.txt file contains the
text “hi”. Write a multithread java application that accomplishes the following tasks concurrently:
• reads the content of file1.txt and displays to the console 200 times
• reads the content of file2.txt and displays the content to the console 150 times
Hint: use BufferedReader object (refer chapter 1 of the course) to read the line of content from
the file