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

Omoops 12

The document outlines an experiment aimed at studying multithreading in Java, including printing tables of numbers and odd/even numbers using threads. It explains the basics of threads, their states, and the importance of synchronization in multithreading. The document also provides a sample Java code demonstrating the implementation of threads for printing odd and even numbers.
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)
8 views3 pages

Omoops 12

The document outlines an experiment aimed at studying multithreading in Java, including printing tables of numbers and odd/even numbers using threads. It explains the basics of threads, their states, and the importance of synchronization in multithreading. The document also provides a sample Java code demonstrating the implementation of threads for printing odd and even numbers.
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

EXPERIMENT 12

AIM : To study Mul threading.-


▪ Print the output of table of 5,7,13 using threads
▪ Print the odd number and even number by thread
OBJECTIVE: Understand mul tasking and implement mul threading.
DESCRIPTION:
*The thread is the smallest unit of dispatchable code. This means that a single program can perform two or
more tasks at once.
*The principal advantage of mul threading is that it enables you to write very efficient programs because it
lets you u lize the idle me that is present in most programs. A thread can be in one of several states. It
can be running. It can be ready to run as soon as it gets CPU me.
* A running thread can be suspended, which is a temporary halt to its execu on. It can later be resumed.
A thread can be blocked when wai ng for a resource.
*A thread can be terminated, in which case its execu on ends and cannot be resumed. Along with thread-
based mul tasking comes the need for a special type of feature called synchroniza on, which allows the
execu on of threads to be coordinated in certain well-defined ways.
*Java’s mul threading system is built upon the Thread class and its companion interface, Runnable. Thread
encapsulates a thread of execu on. To create a new thread, your program will either extend Thread or
implement the Runnable interface.
* The Thread class defines several methods that help manage threads. Here are some of the more commonly used
ones (we will be looking at these more closely as they are used):*All processes have at least one thread of execu on,
which is usually called the main thread, because it is the one that is executed when your program begins.* Crea ng a
ThreadIn the most general sense, you create a thread by instan a ng an object of type Thread. Java defines two ways
in which this can be accomplished:• You can implement the Runnable interface.• You can extend the Thread class,
itself.
CONCLUSION : Thus we studied to handle mul threading.

import java.io.*;

class OddNumbers extends Thread


{
public void run()
{ int
i;
System.out.println("Om Gaikwad"); System.out.println("These
are odd numbers:"); for(i=1;i<=15;i+=2)
{
System.out.println(i);
}
}
}
class EvenNumbers extends Thread
{
public void run()
{ int
i;
System.out.println("These are even numbers:"); for(i=2;i<=18;i+=2)

{
System.out.println(i);
}
}
}
class MainT
{
public sta c void main(String args[])
{
OddNumbers n=new OddNumbers();
Thread t1=new Thread(n);
EvenNumbers n1=new EvenNumbers(); Thread
t2=new Thread(n1);
t1.start(); t2.start();
}
}
Output :

You might also like