0% found this document useful (0 votes)
27 views3 pages

Department of Information Technology

The document is a student's experiment report on demonstrating multithreading in Java. It includes two programs: 1) A simple multithreading program that creates a thread and prints a message. 2) A more complex program that extends the Thread class and prints counting messages from the thread over 4 seconds while the main thread remains alive. The aim was to demonstrate creating and extending threads in Java programs.

Uploaded by

Parvi Agrawal
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)
27 views3 pages

Department of Information Technology

The document is a student's experiment report on demonstrating multithreading in Java. It includes two programs: 1) A simple multithreading program that creates a thread and prints a message. 2) A more complex program that extends the Thread class and prints counting messages from the thread over 4 seconds while the main thread remains alive. The aim was to demonstrate creating and extending threads in Java programs.

Uploaded by

Parvi Agrawal
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/ 3

Department of Information Technology

Academic Year: 2019-20 Name of Student: Piyush Kurkure


Semester: III Student ID:18104031
Class / Branch:IT Date of Performance:14/10/19
Subject:JAVA Date of Submission:14/10/19
Name of Instructor: Rujata Chaudhari

Experiment No. 14

AIM : Write a java program to demonstrate Multithreading in java .

Program1 :
import java.util.*;
class MultithreadingDemo extends Thread
{
public void run()
{
System.out.println("My thread is in running state.");
}
public static void main(String args[])
{
MultithreadingDemo obj=new MultithreadingDemo();
obj.start();
}
}

Output:
Program2:
import java.util.*;
class Count extends Thread
{
Count()
{
super("my extending thread");
System.out.println("my thread is created"+this);
start();
}
public void run()
{
try
{
for(int i=0;i<4;i++)
{
System.out.println("Printing the count"+i);
Thread.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("my thread interrupted");
}
System.out.println("My thread run is over");
}
}
class ExtendingExample{
public static void main(String args[])
{
Count cnt=new Count();
try
{
while(cnt.isAlive())
{
System.out.println("Main thread will be alive till the child thread is
live");Thread.sleep(1500);
}
}
catch(InterruptedException e)
{
System.out.println("Main thread interrupted");
}
System.out.println("Main thread's run is over");
}
}
Output:

You might also like