









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of multi-threading in java, focusing on multi-programming, thread classes, and synchronization. It covers the difference between multi-user, multi-tasking, and multi-threading, the use of thread classes and runnable interfaces, and the importance of thread priorities and states. Additionally, it discusses the concept of critical sections, mutual exclusion, locking, semaphores, monitors, and inter-thread communication.
Typology: Summaries
1 / 16
This page cannot be seen from the preview
Don't miss anything!










➢ (^) Running more than one program that is running multiple programs on a single machine or a computer is known as multi-programming. ➢ (^) The idea of multiprogramming started from the utilisation of the CPU when it is idle as the CPU works for just few time in the whole hour. ➢ (^) There are different form of multi-programming. ➔ (^) Multi-user : more than one user using the machine / running their programs simultaneously.
➢ (^) A single program in java contains one control Flow. ➢ (^) Entry point of the program is main method which executes at First. ➢ Example program: ➢ (^) The second method which executes is the calling method. ➢ (^) The third method which Is executed is the called method. ➢ (^) The above program is example explaining that the main method is the only thread which controls the Flow of the program. ➢ (^) It is just like getting a reference of a page while reading a book. ➢ (^) If there is an inFinite loop in the display method then the Flow of program does not executes further so there needs to be two Flow of controls to execute the program.
➢ Java provides thread class and runnable interface to achieve multithreading. ➢ (^) Thread class contains the actual mechanism for multithreading. ➢ (^) In java a class can extend from only one class. class Test { static void display( ) { s.o.p(“HELLO”); } p.s.v main(…) { display( ); s.o.p(“WORLD”); } }
➢ (^) Example program using runnable interface: Interfaces are implemented. ➢ The class becomes abstract if it does not implements all the features of interface. ➢ (^) In the above program it gives the example that the object also runs when the thread runs.
➢ The First state of the thread is new it stores the object of the thread. ➢ (^) To run the object of thread the start method is called. ➢ (^) When start method is called then it is entered into the ready state where it is ready to run. class My implements Runnable { public void run( ); { Int i= while(true) { s.o.p(i+“hello”); i++; } } } class Test { p.s.v main( ) { My m=new My( ); Thread t=new Thread(m); t.start( ); int i=1; while(true) { s.o.p(i+”world”); i++; } } }
➢ (^) Then it enters into the running state. ➢ (^) After completing the task it will enter into the terminated state. ➢ A thread which is terminated is just like a thread which is killed. ➢ (^) Therefore the different states of thread are NEW! READY! RUNNING! TERMINATED ➢ While running the thread may also enter into different states like:
➢ (^) JAVA supports thread priorities from 1-10. ➢ (^) Execution of threads depends upon scheduler. ➢ (^) If a thread is having higher priority then it should get some preference over other threads. ➢ (^) In java there are different levels of priority that are:
➔ (^) Thread(String name)
➢ There are different methods for the enquirying the thread classes: ➔ (^) boolean isAlive( )
➔ (^) Monitor:
In the above example: