You are on page 1of 1

SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY

SOFTWARE ENGINEERING DEPARTMENT


Fall 202 2
Software Construction and Development (SWE-312)
Assignment 1
Semester: V Batch: 2020F
Due Date: 30-11-2022 Max Marks: 10

Instructions:
Solution must be handwritten. In case of code, attach screenshots of it along with
output.Late Submissionswill not be acknowledged.

Q1) In class, we have studied Deadlock as one of the issues of concurrent software. Livelock
and Starvation are also common concurrency problems which can happen in multithreading
Java programs. Explain both of them with the help of code examples in Java.

Q2) With the help of multithreading, perform the following 2 tasks in 2 separate threads.

For task 1, take the first non-zero digit of your roll no. e.g. 2019-SE-052, here the first
non-zero digit is 5, calculate factorial of 5. The result should be printed like this:
5x4=20
20x3=60
60x2=120
120x1=120
For task 2, use the same number for which you have calculated factorial, and calculate
powers. The result should be printed like this:
51= 5
52= 25
- -
55
= 3125 (to the power 5) end here.

a) Do these tasks in 2 threads concurrently, output should come mixed. Like this,
5x4=20
20x3=60
51= 5
60x2=120
--
--

b) Now use either synchronized method or synchronized statement, and modify your code
to get the output in order. First factorial will be printed then powers in a synchronized manner.

You might also like