Tuesday, 14 February 2017

Java Tutorial: Java Threads (Interrupting a Thread behaves normally | Java thread interrupt)


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

DisplayThread.java
/*
 * Example of interrupting thread that behaves normally.
 *  
 * If thread is not in sleeping or waiting state,
 * calling the interrupt() method sets the interrupted
 * flag to true that can be used to stop the thread by
 * the java programmer later.
 */
class DisplayThread extends Thread
{
    public void run()
    {
        for (int i = 1; i <= 10; i++)
        {
            System.out.println(i);
        }
    }

    public static void main(String args[])
    {
        DisplayThread t1 = new DisplayThread();
        t1.start();

        t1.interrupt();
    }
}
Output
1
2
3
4
5
6
7
8
9
10
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_Interrupt_not_affect_App.zip?attredirects=0&d=1

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

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