Here we will learn about methods in Multithreading
Learn about Join Method : Join method will waiting thread to die.when thread is die scheduler pick another thread available in queue.
- Join Methods
- Sleep Method
- Notify Method
- Notify All
- Resume Method
- Suspend Method
Learn about Sleep method :
- Sleep Method will print a thread value with sleeping time(like 600)
- Thread Sleep specified amount of time
- we will give a time millisecond (given in example or like 600ms)
- exception occur so we will add Exception Object
Example :
class ExampleOfSleep extends Thread{
public void run(){
for (int i=0;i<6;i++){
try {
Thread.sleep(600);
}
catch (InterruptedException e){
System.out.println(e);
}
System.out.print(i+" ");
}
}
public static void main(String[] args) {
ExampleOfSleep e1=new ExampleOfSleep();
e1.run();
}
Output :
Learn about Join Method : Join method will waiting thread to die.when thread is die scheduler pick another thread available in queue.
Example :
public class ExampleOfJoin extends Thread{
public void run() {
for (int i = 0; i < 6; i++) {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
System.out.println(e);
}
System.out.print(i+" ");
}
}
public static void main(String[] args) {
ExampleOfJoin e1=new ExampleOfJoin();
ExampleOfJoin e2=new ExampleOfJoin();
ExampleOfJoin e3=new ExampleOfJoin();
e1.start();
try {
e1.join();
}
catch (Exception e){
System.out.println(e);
}
e2.start();
e3.start();
}
}
Output :
More About Important Method is used in Multithreadings :
- start() : start method is used to execution of the thread
- run() : run method is used to do task for thread
- getPriority : getPriority method is used to return priority of thread
- setPriority : setPriority method is used to set the priority of thread
- setName() : setName method is used to set the name of thread
- getName() : getName method is used to get the name of thread
- getId() : getId method is used to get id of thread
- isAlive : isAlive method is used to test the if the thread is alive
- suspend() : suspend method is used to suspend the thread
- resume() : resume method is used to resume the suspended thread
- stop() : stop method is used to stop the thread
- notify() : notify method is used to notify one thread which is waiting for a particular object
- notifyAll() : notifyAll method is used All thread which is waiting for a particular object.
Sorting and Searching Programs
Start with your Choice
-Important Programs for Freshers
- Palindrome Number
- Prime
Number
- Swapping
Number
- Leap
Year
- Odd
and Even Number
- Fibonacci
Series
- Armstrong
Number
- Factorial
Number
- Print
Table
Learn Pattern Programs
- Alphabet pattern program in java
- Star Pattern
Programs in Java
- Square pattern programs in java
- Diamond Star pattern programs in java
- Number Pattern Programs in java
- Diagonal
pattern program in java
Click to learn Array Programs
- 4 ways to print Array in Java
- 2-D Array in Java
- Anonymous Array in Java
- Single Dimensional Array in Java
- Find Second Largest Number in Array
- Delete an Element in Array in Java
- Common Element in Array in Java
- Missing Element in Array
- Insert Element in Array
- Reverse Array
in Java
- Merge Two
Array in Java
- Smallest and Largest Elements in Array
- Find
Odd and Even Number in Array
Click to Learn MySQL
for any complaint regarding my Blog please
visit contact us page
and write what problem you have!
No comments:
Post a Comment