Multitreading Document
Multitreading Document
package demotest;
public class thread_example1 implements Runnable {
@Override
public void run() {
}
public static void main(String[] args) {
Thread guruthread1 = new Thread();
guruthread1.start();
try {
guruthread1.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
guruthread1.setPriority(1);
int gurupriority = guruthread1.getPriority();
System.out.println(gurupriority);
System.out.println("Thread Running");
}
}
Code Line 6: Here we have defined the main method in which we will start the
execution of the thread.
Code Line 8: we will use "start" method of the thread using "guruthread1"
instance. Here the thread will start executing.
Code Line 10: Here we are using the "sleep" method of the thread using
"guruthread1" instance. Hence, the thread will sleep for 1000 milliseconds.
Code 9-14: Here we have put sleep method in try catch block as there is
checked exception which occurs i.e. Interrupted exception.
Code Line 15: Here we are setting the priority of the thread to 1 from whichever
priority it was
Code Line 16: Here we are getting the priority of the thread using getPriority()
Code Line 17: Here we are printing the value fetched from getPriority
Code Line 18: Here we are writing a text that thread is running.
When you execute the above code, you get the following output: