Wednesday, 30 November 2016

Java Tutorial : Java Threads (How to create a thread in java | Runnable interface in java)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=aq7M06XlfEI&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Threads (How to create a thread in java | Runnable interface in java) 
Java Tutorial : Java Threads (How to create a thread in java | Runnable interface in java) 
 DisplayRunnable.java
/*
 * If you are not extending the Thread class,your class
 * object would not be treated as a thread object.So you
 * need to explicitly create Thread class object.We are
 * passing the object of your class that implements
 * Runnable so that your class run() method may execute.
 */
public class DisplayRunnable implements Runnable
{
    public static void main(String args[])
    {
        DisplayRunnable displayRunnable = new DisplayRunnable();
        Thread thread = new Thread(displayRunnable);
        thread.start();
    }

    /*
     * When an object implementing interface Runnable is
     * used to create a thread, starting the thread causes
     * the object's run method to be called in that
     * separately executing thread.
     */
    @Override
    public void run()
    {
        System.out.println("Hello Peter..");
    }
}
Output
Hello Peter..

Refer: 
https://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/Thread_create_Runnable_app.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/Thread_create_Runnable_app

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/5edb9b935a4ef60d2a672d03f038390cd08d4eb7/BasicJava/Thread_create_Runnable_app/?at=master

See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment