Modern computers are generally multi-CPU and multi-core, and the traditional program is single-threaded, only running on a core, it will waste these computing resources, so the invention of multi-threading to make full use of them. This works even on a single CPU, because most of the time the computation is waiting for I/O so that another thread can run. The main task of modern operating system is to schedule processes and threads. As we delve deeper into the operating system, we are bound to find a busy scene.

Run () : newthread.java (newthread.java) : newthread.java (newthread.java)

public class NewThread implements Runnable { public void run() { try { for(int i = 5; i > 0; I -) {system.out.println (“Child Thread: “+ I); Thread.sleep(100); }} catch (Exception e) {} system.out.println (” child thread exit. “); }} Defining a thread is as simple as implementing the Run () method of the Runnable interface. Here we write very simply, print out a sentence, sleep for 100ms, loop 5 times and exit.

We will also write a program that uses the thread program as follows (threaddemo.java) :

public class ThreadDemo {

public static void main(String[] args) {

Thread t = new Thread(new N