TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Wednesday, 15 April 2020

Java Thread Run() Method | Java Thread Run Method Throws Exception | Java Thread Multiple Run Methods

Java Thread run() method

The run() method of thread class is called if the thread was constructed using a separate Runnable object otherwise this method does nothing and returns. When the run() method calls, the code specified in the run() method is executed. You can call the run() method multiple times.
The run() method can be called using the start() method or by calling the run() method itself. But when you use run() method for calling itself, it creates problems.

java thread run method throws exception


Fig: Thread Run Method


Return

             It does not return any value.  

Example: 

call the run() method using the start() method
       public class RunExp1 implements Runnable  
      {    
    public void run()  
    {    
        System.out.println("Thread is running...");    
    }    
    public static void main(String args[])  
    {    
        RunExp1 r1=new RunExp1();    
        Thread t1 =new Thread(r1);    
        // this will call run() method   
        t1.start();    
    }    
        }  

Output:

         Thread is running...

No comments:

Post a Comment