0% found this document useful (0 votes)
9 views6 pages

Processes: Distributed Systems Principles and Paradigms

The document discusses processes and threads in distributed systems, explaining that threads are virtual processors in software that run on top of physical processors and allow stopping the current execution and continuing it later, while a process contains one or more threads. It provides examples of creating and running threads in Java and how they allow concurrency by executing code simultaneously through examples that print output from multiple threads.

Uploaded by

Rodel D Dosano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Processes: Distributed Systems Principles and Paradigms

The document discusses processes and threads in distributed systems, explaining that threads are virtual processors in software that run on top of physical processors and allow stopping the current execution and continuing it later, while a process contains one or more threads. It provides examples of creating and running threads in Java and how they allow concurrency by executing code simultaneously through examples that print output from multiple threads.

Uploaded by

Rodel D Dosano
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 6

DISTRIBUTED SYSTEMS

Principles and Paradigms


Second Edition
ANDREW S. TANENBAUM
MAARTEN VAN STEEN

Chapter 3
Processes

Tanenbaum & Van Steen,


Distributed Systems: Principles and
Paradigms, 2e, (c) 2007 Prentice-
Hall, Inc. All rights reserved. 0-13-
Example: Java
main thread-
minor thread by main thread (share-
cpu time)
last terminated thread: main thread-

}class mythread
}public static void main(String[]args)
; Thread t
)(;t=Thread.currentThread
System.out.println(t); Thread[main,5,main]
;t.setName(thread1)
System.out.println(t);--> Thread[thread1,5,main]
Example: thread creation
}class Thread2 extends Thread
)(}public Thread2 T0RG
;{System.out.println(second thread starting)

)(}public void run


for(int i=0;i<500;i++) T0RL
{;System.out.println(turn second+i)
}
T1RG
}class mainthread
}Public static void main(Sting[]args)
Thread2 t=new Thread2(); t.start(); concurrency T1RL
for(int i=0;i<500;i++)
;{System.out.println(turn main:+i)
}
example
}class Newthread extends Thread
)(} public void run

}try
}for(int i=0;i<500;i++)
;System.out.println(child is sleeping)
{;{ Thread.sleep(2000)

}catch(InterruptedException e)
;{System.out.println(child interrupted)
;System.out.println(exit
cont. next
child)
<. } page
From previous pag
}class mainthread
}public static void main(String[]args)
;System.out.println(befor.)

;)(Newthread t1=new Newthread(); t1.start


;System.out.println(after.)

}try
}For(int j=0;j<500;j++)
;System.out.println(main starting:+j)
;Thread.sleep(2000)
{)(;{ If(j==25) t1.Interrupt

}catch(InterruptedException e)
;{System.out.println(main interrupted)
;System.out.println(exit main)
}
Threads

thread: virtual processors )VP( in software, on top of


physical processors

VP: set of instructions

stopping the current VP and saving all the data


.needed to continue the execution at a later stage

Process: actual software processor threads
lightweight process = thread

You might also like