0% found this document useful (0 votes)
34 views1 page

Sample Exercises For The Lab Exam

The document provides instructions for three exercises on writing multi-threaded Java applications. The first exercise has two threads concurrently printing strings 300 and 600 times. The second exercise has three threads concurrently printing strings 300 times, printing the first 300 multiples of 7, and printing the first 400 multiples of 9. The third exercise has two threads concurrently reading and displaying the contents of two text files to the console 150-200 times each.

Uploaded by

lata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Sample Exercises For The Lab Exam

The document provides instructions for three exercises on writing multi-threaded Java applications. The first exercise has two threads concurrently printing strings 300 and 600 times. The second exercise has three threads concurrently printing strings 300 times, printing the first 300 multiples of 7, and printing the first 400 multiples of 9. The third exercise has two threads concurrently reading and displaying the contents of two text files to the console 150-200 times each.

Uploaded by

lata
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Advanced Programming (ITec3054)

Worksheet for Multi-thread programming in java

Exercise 1: Write a multi-thread java application that performs the following two tasks
concurrently:

• prints the string “AP test” 300 times


• prints the string “today” 600 times

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:

• prints the string “AP test” 300 times


• print the first 300 multiples of 7
• print the first 400 multiples of 9

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

You might also like