Friday, 9 December 2016

Java Tutorial : Java Threads (Thread start method)


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

Click the below Image to Enlarge
Java Tutorial : Java Threads (Thread start method) 
ThreadExample.java
public class ThreadExample
{
    public static void main(String[] args)
    {
        /*
         * It prints out the name of the thread executing
         * the main() method. This thread is assigned by the
         * JVM.
         */
        System.out.println(Thread.currentThread().getName());

        /*
         * It starts up 10 threads and give them all a
         * number as name ("" + i). Each thread then prints
         * its name out, and then stops executing.
         */
        for (int i = 0; i < 10; i++)
        {
            new Thread("" + i)
            {
                public void run()
                {
                    try
                    {
                        Thread.sleep(100);
                    }
                    catch (InterruptedException e)
                    {
                        e.printStackTrace();
                    }
                    System.out.println("Thread: " + getName() + " running");
                }
            }.start();
        }
    }
}
Output
main
Thread: 9 running
Thread: 2 running
Thread: 5 running
Thread: 6 running
Thread: 1 running
Thread: 8 running
Thread: 3 running
Thread: 4 running
Thread: 7 running
Thread: 0 running

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

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8227d2165e265b2a41b3dbc1ecd1f352fea3b3f5/BasicJava/ThreadDemo_Start_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

    Google+ Followers

    Google+ Badge