kodejava-lang-package/src/main/java/org/kodejava/example/lang/ThreadDemo.java
private static synchronized void sayHello() {
        for (int i = 0; i < 10; i++) {
            System.out.println("Thread [" + Thread.currentThread().getName() +  "] ==> Hi...");
        }

        try {
            // Causes the currently executing thread to sleep for a random
            // milliseconds
            Thread.sleep((long) (Math.random() * 1000 + 1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // Causes the currently executing thread object to temporarily pause
        // and allow other threads to execute.
        Thread.yield();
    }
/**
     * The synchronized modifier ensure that two threads cannot execute the block
     * at the same time.
     */
The synchronized modifier ensure that two threads cannot execute the block
at the same time.
The synchronized modifier ensure that two threads cannot execute the block at the same time .
private static synchronized void sayHello() {
        for (int i = 0; i < 10; i++) {
            System.out.println("Thread [" + Thread.currentThread().getName() +  "] ==> Hi...");
        }
        try {
            Thread.sleep((long) (Math.random() * 1000 + 1000));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Thread.yield();
    }
private static synchronized void sayHello ( ) { for ( int i = 0 ; i < 10 ; i ++ ) { System . out . println ( "Thread [" + Thread . currentThread ( ) . getName ( ) + "] ==> Hi..." ) ; } try { Thread . sleep ( ( long ) ( Math . random ( ) * 1000 + 1000 ) ) ; } catch ( InterruptedException e ) { e . printStackTrace ( ) ; } Thread . yield ( ) ; }
The synchronized modifier ensure that two threads cannot execute the block
 at the same time.
The synchronized modifier ensure that two threads cannot execute the block at the same time .
// Causes the currently executing thread to sleep for a random // milliseconds // Causes the currently executing thread object to temporarily pause // and allow other threads to execute.