Experiment_13_
Experiment_13_
Year 2024-25
Name- Mohammad Ahmed Shaikh
Sap id – 60003240302
Roll no-I169
}
public void run() {
System.out.println("Table of " + number + ":");
for (int i = 1; i <= 10; i++) {
Output:
System.out.print("/*");
}
}
t2.start();
}
}
Output:
c. Write a multithreaded program that generates the Fibonacci sequence. This program should
work as follows: create a class Input that reads the number of Fibonacci numbers that the
program is to generate. The class will then create a separate thread that will generate the
Fibonacci numbers, placing the sequence in an array. When the thread finishes execution,
the parent thread (Input class) will output the sequence generated by the child thread.
Because the parent thread cannot begin outputting the Fibonacci sequence until the child
thread finishes, the parent thread will have to wait for the child thread to finish.
Output:
d. WAP to prevent concurrent booking of a ticket using the concept of thread synchronization.
Code: class TicketSystem
{ int
availableTickets = 3;
} else {
System.out.println(name + " failed to book. No tickets left.");
}
}
}
Object Oriented Programming using Java Laboratory (DJS23FLES201) Academic Year
2024-25
}
Object Oriented Programming using Java Laboratory (DJS23FLES201) Academic Year
2024-25
Output:
e. Write a program to demonstrate thread methods: wait notify suspend resume join setpriority
getpriority setname getname Code: class
EXP13e extends Thread {
Thread.sleep(500);
} catch (InterruptedException e) {
System.out.println("Thread interrupted.");
}
}
}
}
Output: