oopex8
oopex8
4/10/24 URK23AI1035
Aim :
Description :
Syntax:
• You need to create a Thread object using a constructor that takes a Runnable object and a
thread name as parameters.
Syntax:
• After creating the Thread object, you start the thread by calling the start() method,
which in turn calls the run() method.
Syntax:
threadObj.start();
• You override the run() method in your class to provide the logic that the thread will
execute.
Syntax:
• Once you have created an object of your class, you can start the thread by calling the
start() method, which will execute the overridden run() method.
Syntax:
Program :
1.
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
System.out.println("Thread interrupted.");
[Type here]
System.out.println("URK23AI1021--PIO MICHEAL");
thread.start();
}OUTPUT:
2.
import java.util.Scanner;
number1 = scanner.nextInt();
number2 = scanner.nextInt();
@Override
@Override
if (UserInputThread.number2 != 0) {
} else {
@Override
int sum = 0;
sum += i;
{ System.out.println("URK23AI1021--PIO MICHEAL");
t1.setName("t1");
t2.setName("t2");
t3.setName("t3");
t4.setName("t4");
t1.start();
OUTPUT :
[Type here]
RESULT :
The program for multithreading has been completed and output is verified successfully