Beruflich Dokumente
Kultur Dokumente
Defining Threads
Threaded Applications
Application Level
Bottom Line:
Illusion of concurrency
Threaded Applications
Modern Systems
office automation
multimedia
Multitasking
Multitasking
pictures
..
}
begin
body
end
}
5
Threaded Applications
Modern Systems
GUI rendering
A Multithreaded Program
Main Thread
start
Thread A
start
start
Thread B
Thread C
Multi-threaded Process
Threads of
Execution
Modern Applications
Web/FTP
server
Client 2
Client N
Threaded Applications
Modern Applications
Favorities, Share,
Comments Posting
Java Threads
currentThread
yield
sleep
resume
start
run
stop
setPriority
getPriority
suspend
Threading Mechanisms...
MyThread
Runnable
Thread
MyClass
Create a thread:
MyThread thr1 = new MyThread();
Start Execution of threads:
thr1.start();
Create and Execute:
new MyThread().start();
13
An example
class MyThread extends Thread {
public void run() {
System.out.println(" this thread is running ... ");
}
}
class ThreadEx1 {
public static void main(String [] args ) {
MyThread t = new MyThread();
t.start();
}
}
14
Creating Object:
MyThread myObject = new MyThread();
Start Execution:
thr1.start();
15
An example
class MyThread implements Runnable {
public void run() {
System.out.println(" this thread is running ... ");
}
}
class ThreadEx2 {
public static void main(String [] args ) {
Thread t = new Thread(new MyThread());
t.start();
}
}
16
ready
notify()
waiting
wait()
resume()
Time expired/
interrupted
sleeping
blocked
dispatch
sleep()
running
suspend()
Block on I/O
completion
stop()
dead
17
Thread Priority
ThreadName.setPriority(intNumber)
MIN_PRIORITY = 1
NORM_PRIORITY=5
MAX_PRIORITY=10
18
Deposit()
Withdraw()
Enquire()
19
Bank
Bank Operator
Operator 11
Bank
Bank Local
Local Area
Area Network
Network
Client
Client 22
Bank
Bank Operator
Operator M
M
Client
Client N
N
Bank
Bank Database
Database
Shared Resources
}
21
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
22