Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java multi-threaded in a three way (inheritance, implementation, anonymous inner classes)     - Hadoop 0.23 compile common errors (Server)

- Android Qemu GPS module (Programming)

- Shilpa Nair interview experience sharing RedHat Linux package management (Linux)

- Bash common several configuration files (Linux)

- Configuring Allatori code confusion when developing general Java applications in NetBeans (Programming)

- How to configure HTTP Strict Transport Security (HSTS) (Linux)

- Database Blob data type conversion String (Programming)

- Shared directory settings between Linux and Linux (Linux)

- Vagrant Getting Start (Linux)

- java.net.NoRouteToHostException of Hadoop problem: no route to host (Server)

- To install Xen in Ubuntu 12.04 (Linux)

- Report generation CPU, memory, and input and output ports with the sar command (Linux)

- Use JMS listener Oracle AQ, trigger the execution of Java programs in the database changes (Database)

- A detailed introduction to the Hadoop ecosystem (Server)

- Linux security settings Notes (Linux)

- OpenvSwitch 2.1.2 shell script to start and stop (Linux)

- Installation of Gitlab under Ubuntu (Linux)

- Shell Scripting Basics (Linux)

- List Leaves (Programming)

- Repair Raspbian Encountered a section with no Package (Linux)

 
         
  Java multi-threaded in a three way (inheritance, implementation, anonymous inner classes)
     
  Add Date : 2018-11-21      
         
         
         
  Java multi-threaded in a three way (inheritance, implementation, anonymous inner classes)

/ ** The first way: inheritance Thread class

* 1. Define a class, and then let the class inheritance Thread class

* 2. The method of rewriting run

* 3. Create defined objects of this class

* 4. Start the thread

* /

// Inheritance Thread class

public class MyThread extends Thread {
    
    public MyThread () {}

    public MyThread (String name) {
        super (name);
    }

    // Run method of packaging codes should be a thread of execution, in principle, run method code, party general store are relatively time-consuming code
    public void run () {
        
        for (int i = 0; i <200; i ++) {
            
            System.out.println (Thread.currentThread () getName () + "---" + i.);
        }
    }
}

//Test Methods

private static void Test () {

// Create an object
        MyThread mt1 = new MyThread ();
        MyThread mt2 = new MyThread ();


        // Start the thread
        // Public void start () Causes this thread to begin execution; Java Virtual Machine calls the run method of this thread.
        mt1.start ();
        Start threads only once //mt1.start();//
        mt2.start ();

}

-------------------------------------------------- -------------------------------------------------- --------

/ ** The second way: to achieve Runnable interface

* (1): to create a class, the class to implement Runnable

* (2): rewrite the run method

* (3): to create objects of this class

* (4): Create a Thread class object, and then pass parameters to the object as 3 Thread

* (5): Start a thread

* /

// Implement Runnable

public class MyThread2 implements Runnable {
    
  public MyThread2 () {
        super ();
      }

      public void run () {
        
          for (int x = 0; x <200; x ++) {
            
            System.out.println (Thread.currentThread () getName () + "---" + x.);
        }
    }
}

//Test Methods

    private static void Test2 () {

// Create an object MyThread
        MyThread2 mt = new MyThread2 ();
        // Create Thread objects of the class, and then the 3 object as a parameter passed to the Thread
        // Public Thread (Runnable target)
        Thread t1 = new Thread (mt, "Zhang Fei");
        Thread t2 = new Thread (mt, "Guan Yu");
        Thread t3 = new Thread (mt, "Liu Bei");
        // Start the thread
        t1.start ();
        t2.start ();
        t3.start ();
    }

-------------------------------------------------- -------------------------------------------------- --------

 

/ ** The third way: Using anonymous inner class way to achieve

* New class name / interface name () {

* The method of rewriting;

*};

* /

//Test Methods

// Anonymous inner classes

    private static void Test3 () {

new Thread () {
          public void run () {
                System.out.println ( "thread executes .......");
            }
        } .start ();
    }
     
         
         
         
  More:      
 
- CentOS7 installation performance monitoring system (Server)
- Oracle 12C RAC on temporary table space Enlighten (Database)
- Java JDK has been able to compile without warning (Programming)
- Axel install plug under CentOS 5/6 acceleration yum downloads (Linux)
- Android 4.2 compilation notes (Programming)
- Print Linux system error codes (Linux)
- C ++ 11 feature: decltype keywords (Programming)
- 7 extremely dangerous Linux commands (Linux)
- JavaScript function closures Quick Start (Programming)
- Share useful bash aliases and functions (Linux)
- Error: Unable to establish connection with FTP SFTP server (Server)
- Alternative methods of intrusion bundled executable file new thinking (Linux)
- To share Linux script automatically change passwords (Linux)
- Installation in lxml Python module (Linux)
- How to contribute code on GitHub uploads (Linux)
- Linux, Oracle listen address modification (Database)
- Ubuntu Locale configuration problem solving Can not set LC_CTYPE (Linux)
- Ubuntu batch scp to copy files without password (Linux)
- How to deploy Python Web application: Heroku deployment process complete records (Server)
- To use iostat display I / O status under Linux (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.