Search

Content

Java Multi Threading8/01/2019
Java Multi Threading

1.Introduction
2.how many ways to define the thread
      by extending the thread class
      by implementing runnable interface
3. setting and getting name of threads
4.Thread priorites
5.the methods to prevent thread execution
     yield
     join
     sleep
6. Synchronization
7.Internal Thread Communication
8. Dead lock
9. Demon Threads
10.Multi Threading Enhancements


Multi Tasking
categorized into two types
   1.process based( where each task is different task and executed separately )
   2. Thread based( where single task is executed independently as process)

2. Defining a thread

We can define a thread 2 wasys.
1.by extending a thread the thread class.

     class mythread extends Thread{
        public void run(){
             sop ("child cthread")
        }
    }

p s v main(){
      mythred t = new mythread(); // instantiation 
     t.start(); // starting a thread


}

difference b/w t.start & t.run
t.start(): a seperated flow will be created.
t.run(): normal call as function

2.by implementing runnable interface.


Thread.start() internal implementation
1.thread schedular will register the thread
2. perferorm all other mandatory formalties
3.invoke run methdod