Thursday, 16 February 2017

Java Tutorial : Java Threads (Thread vs Runnable) - Playlist

Java Tutorial : Java Threads (Thread vs Runnable_V1)


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

Click the below Image to Enlarge
Java Tutorial : Java Threads (Thread vs Runnable_V1) 
Java Tutorial : Java Threads (Thread vs Runnable_V1) 
Java Tutorial : Java Threads (Thread vs Runnable_V1) 
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
  • Java Tutorial: Java Synchronization (Static synchronization in Java) - Playlist

    Java Tutorial: Java Synchronization (Static synchronization Vs. Non static Synchronization)


    Click here to watch in Youtube :
    https://www.youtube.com/watch?v=Gx1ORA-b-OQ&list=UUhwKlOVR041tngjerWxVccw

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Static synchronization Vs. Non static Synchronization) 
    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
  • Java Tutorial: Java Synchronization (Static synchronization block | Synchronization in java)


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

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Static synchronization block | Synchronization in java) 
    StaticSynchronizationDemo.java
    class Table
    {
    
        static void printTable(int n)
        {
            /*
             * The block synchronizes on the lock of the object
             * denoted by the reference .class name .class
             */
            synchronized (Table.class)
            {
                System.out.println(Thread.currentThread().getName());
                for (int i = 1; i <= 5; i++)
                {
                    System.out.println(n * i);
                    try
                    {
                        Thread.sleep(400);
                    }
                    catch (Exception e)
                    {
                    }
                }
                System.out.println("------------------------");
            }
        }
    }
    
    public class StaticSynchronizationDemo
    {
        public static void main(String t[])
        {
            Thread t1 = new Thread()
            {
                public void run()
                {
                    Table.printTable(1);
                }
            };
    
            Thread t2 = new Thread()
            {
                public void run()
                {
                    Table.printTable(10);
                }
            };
    
            t1.start();
            t2.start();
        }
    }
    
    Output
    Thread-0
    1
    2
    3
    4
    5
    ------------------------
    Thread-1
    10
    20
    30
    40
    50
    ------------------------
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_static_synchronization_block_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/d83d752fbc13c2d1cd6c6655b89d6e57fdda2f22/BasicJava/ThreadDemo_static_synchronization_block_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
  • Java Tutorial: Java Synchronization (Static synchronization method[asynchronous thread])


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

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Static synchronization method[asynchronous thread]) 
    StaticSynchronizationDemo.java
    /*
     * In this example, we are using anonymous class to create the threads.
     */
    
    class Table
    {
    
        synchronized static void printTable(int n)
        {
            System.out.println(Thread.currentThread().getName());
            for (int i = 1; i <= 5; i++)
            {
                System.out.println(n * i);
                try
                {
                    Thread.sleep(400);
                }
                catch (Exception e)
                {
                }
            }
            System.out.println("------------------------");
        }
    }
    
    public class StaticSynchronizationDemo
    {
        public static void main(String t[])
        {
            Thread t1 = new Thread()
            {
                public void run()
                {
                    Table.printTable(1);
                }
            };
    
            Thread t2 = new Thread()
            {
                public void run()
                {
                    Table.printTable(10);
                }
            };
    
            t1.start();
            t2.start();
    
        }
    }
    
    Output
    Thread-0
    1
    2
    3
    4
    5
    ------------------------
    Thread-1
    10
    20
    30
    40
    50
    ------------------------
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_static_sync_method_anonymous_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/d83d752fbc13c2d1cd6c6655b89d6e57fdda2f22/BasicJava/ThreadDemo_static_sync_method_anonymous_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
  • Java Tutorial: Java Synchronization (Static synchronization method | Synchronization in java)


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

    Click the below Image to Enlarge
    Java Tutorial: Java Synchronization (Static synchronization method | Synchronization in java) 
    StaticSynchronizationDemo.java
    class Table
    {
    
        /*
         * We are applying synchronized keyword on the static
         * method to perform static synchronization.
         */
        synchronized static void printTable(int n)
        {
            System.out.println(Thread.currentThread().getName());
            for (int i = 1; i <= 5; i++)
            {
                System.out.println(n * i);
                try
                {
                    Thread.sleep(400);
                }
                catch (Exception e)
                {
                }
            }
            System.out.println("------------------------");
        }
    }
    
    class MyThread1 extends Thread
    {
        public void run()
        {
            Table.printTable(1);
        }
    }
    
    class MyThread2 extends Thread
    {
        public void run()
        {
            Table.printTable(10);
        }
    }
    
    public class StaticSynchronizationDemo
    {
        public static void main(String t[])
        {
            MyThread1 t1 = new MyThread1();
            MyThread2 t2 = new MyThread2();
            t1.start();
            t2.start();
    
        }
    }
    
    Output
    Thread-1
    10
    20
    30
    40
    50
    ------------------------
    Thread-0
    1
    2
    3
    4
    5
    ------------------------
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_static_synchronization_method_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/d83d752fbc13c2d1cd6c6655b89d6e57fdda2f22/BasicJava/ThreadDemo_static_synchronization_method_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
  • Wednesday, 15 February 2017

    Java Tutorial: Java Threads (The difference between wait and sleep in java_V2)


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

    Click the below Image to Enlarge
    Java Tutorial: Java Threads (The difference between wait and sleep in java_V2) 
    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
  • Java Threads (The difference between wait and sleep in java) - Playlist

    Java Tutorial: Java Threads (The difference between wait and sleep in java_V1)


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

    Click the below Image to Enlarge
    Java Tutorial: Java Threads (The difference between wait and sleep in java_V1) 
    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
  • Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication)


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

    Click the below Image to Enlarge
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 
    Java Tutorial: Java Threads (Inter thread communication in java | java inter thread communication) 

    InterthreadCommunitcationDemo.java
    class InterthreadCommunitcationDemo
    {
        public static void main(String args[])
        {
            final BankAccount bankAccount = new BankAccount();
            
            new Thread("Thread 1")
            {
                public void run()
                {
                    bankAccount.withdraw(50000);
                }
            }.start();
            
            new Thread("Thread 2")
            {
                public void run()
                {
                    bankAccount.deposit(80000);
                }
            }.start();
    
        }
    }
    
    BankAccount.java
    class BankAccount
    {
        private int amount = 10000;
    
        synchronized void withdraw(int amount)
        {
            System.out.println("Going to withdraw...");
    
            if (this.amount < amount)
            {
                System.out.println("Less balance; waiting for deposit...");
                try
                {
                    wait();
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            this.amount -= amount;
            System.out.println("Withdraw completed...");
        }
    
        synchronized void deposit(int amount)
        {
            System.out.println("Going to deposit...");
            this.amount += amount;
            System.out.println("Deposit completed... ");
            notify();
        }
    }
    
    Output
    Going to withdraw...
    Less balance; waiting for deposit...
    Going to deposit...
    Deposit completed... 
    Withdraw completed...
    
    Refer: 
    https://docs.oracle.com/javase/8/docs/api/index.html?java/lang/Object.html

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

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/d83d752fbc13c2d1cd6c6655b89d6e57fdda2f22/BasicJava/Thread_InterthreadCommunitcation_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
  • Tuesday, 14 February 2017

    Java Tutorial: Java Threads (How to check thread is interrupted using interrupted methods)


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

    DisplayThread.java
    class DisplayThread extends Thread
    {
        public void run()
        {
    
            /*
             * Tests whether this thread has been interrupted.
             * The interrupted status of the thread is
             * unaffected by this method.
             */
            System.out.println("Before Thread.interrupted() is called = "
                    + Thread.currentThread().isInterrupted());
    
            /*
             * Tests whether the current thread has been
             * interrupted. The interrupted status of the thread
             * is cleared by this method.
             */
            if (Thread.interrupted())
            {
    
                System.out.println("After Thread.interrupted() is called = "
                        + Thread.currentThread().isInterrupted());
                System.out.println("code for interrupted thread");
            }
            else
            {
                System.out.println("code for normal thread");
            }
        }
    
        public static void main(String args[])
        {
            DisplayThread t1 = new DisplayThread();
            t1.start();
            t1.interrupt();
        }
    }
    
    Output
    Before Thread.interrupted() is called = true
    After Thread.interrupted() is called = false
    code for interrupted thread
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_interrupted_methods_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c6d02f88f8ab0956ad4accc8fd295e2d284f7fba/BasicJava/ThreadDemo_interrupted_methods_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
  • 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
  • Java Tutorial: Java Threads (How to handle Interrupted exception | Java thread interrupt)


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

    DisplayThread.java
    /*
     * Example of interrupting a thread that doesn't stop
     * working
     * 
     * In this example, after interrupting the thread, we
     * handle the exception, so it will break out the
     * sleeping but will not stop working.
     */
    
    class DisplayThread extends Thread
    {
    
        public void run()
        {
            try
            {
                System.out.println("Going to sleep...");
                Thread.sleep(1000);
                System.out.println("Welcome to India...");
            }
            catch (InterruptedException e)
            {
                System.out.println("Exception handled");
            }
            System.out.println("Thread is running...");
        }
    
        public static void main(String args[])
        {
            DisplayThread t1 = new DisplayThread();
            t1.start();
            try
            {
                t1.interrupt();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
        }
    }
    
    Output
    Going to sleep...
    Exception handled
    Thread is running...
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_Handle_Interrupted_Exe_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/c6d02f88f8ab0956ad4accc8fd295e2d284f7fba/BasicJava/ThreadDemo_Handle_Interrupted_Exe_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
  • Thursday, 9 February 2017

    Java Tutorial : Java Threads (Java thread interrupt) - Playlist

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


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

    Click the below Image to Enlarge
    Java Tutorial: Java Threads (Interrupting a Thread | Java thread interrupt) 
    Java Tutorial: Java Threads (Interrupting a Thread | Java thread interrupt) 
    DisplayThread.java
    /*
     * Example of interrupting a thread that stops
     * working.
     * 
     * In this example, after interrupting the thread, we
     * are propagating it, so it will stop working. If we
     * don't want to stop the thread, we can handle it where
     * sleep() or wait() method is invoked.
     */
    class DisplayThread extends Thread
    {
    
        public static void main(String args[])
        {
            DisplayThread t1 = new DisplayThread();
            t1.start();
            try
            {
                t1.interrupt();
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
    
        }
    
        public void run()
        {
            try
            {
                System.out.println("Going to sleep...");
                Thread.sleep(1000);
                System.out.println("Welcome to India...");
            }
            catch (InterruptedException e)
            {
                throw new RuntimeException("Thread interrupted... " + e);
            }
    
        }
    
    }
    
    Output
    Exception in thread "Thread-0" Going to sleep...
    java.lang.RuntimeException: Thread interrupted... 
    java.lang.InterruptedException: sleep interrupted
        at DisplayThread.run(DisplayThread.java:38)
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_Interrupting_Thread_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/644abf74fceeb240066dd3d2fe2e4b1fb6c4bd48/BasicJava/ThreadDemo_Interrupting_Thread_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
  • Java Tutorial Java Thread (Reentrant monitor | Reentrant lock in java)


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

    Click the below Image to Enlarge
    Java Tutorial Java Thread (Reentrant monitor | Reentrant lock in java)
    DisplayMessage.java
    class DisplayMessage
    {
        /*
         * Declaring two synchronized method displayName() and
         * displayHello().one synchronized method calling to
         * another one.
         */
        public synchronized void displayName()
        {
            displayHello();
            System.out.println("Peter");
        }
    
        public synchronized void displayHello()
        {
            System.out.print("Hello ");
        }
    }
    
    ReentrantExample.java
    public class ReentrantExample
    {
        public static void main(String args[])
        {
            Thread t1 = new Thread()
            {
                public void run()
                {
                    new DisplayMessage().displayName();
                }
            };
            t1.start();
        }
    }
    
    Output
    Hello Peter
    
    
    Click the below link to download the code:
    https://sites.google.com/site/ramj2eev1/home/javabasics/Thread_ReentrantDemo_App.zip?attredirects=0&d=1

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

    Bitbucket Link:
    https://bitbucket.org/ramram43210/java/src/644abf74fceeb240066dd3d2fe2e4b1fb6c4bd48/BasicJava/Thread_ReentrantDemo_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
  • Google+ Followers

    Google+ Badge