Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Multi Threading Main thread Thread.currentThread() Default priority of the main thread is 5 Minimum Priority -- 1 Maximum Priority -- 10 Normal Priority -- 5 getPriority() setPriority(int) getName() setName(String) start() interrupt() throws InterruptedException static sleep(long) throws...

Multi Threading Main thread Thread.currentThread() Default priority of the main thread is 5 Minimum Priority -- 1 Maximum Priority -- 10 Normal Priority -- 5 getPriority() setPriority(int) getName() setName(String) start() interrupt() throws InterruptedException static sleep(long) throws InterruptedException sleep(long, long) throws InterruptedException join() throws InterruptedException wait() throws InterruptedException wait(long) throws InterruptedException wait(long, long) throws InterruptedException notify() notifyAll() Create Thread 1. Extending Thread class 2. Implementing Runnable interface Runnable interface has only one method public void run() The code which you want execute by a thread must be written in the run() method A thread is executed using a start() method of the Thread class. Start() method will in-turn call the run() method We can create multiple thread by creating multiple objects of the Child Thread class Example : class Ex extends Thread {...... public void run() {.... } public static viod main() { Ex t1 = new Ex(); Ex t2 = new Ex(); t1.start(); t1.start(); } } If we want a method/block to be executed by only one thread at a time then the method should synchronized Example : Synchronized public void show() { } Example : public void show() { synchronized { } } GUI Components

Use Quizgecko on...
Browser
Browser