Java
IBM
Recherches
Sites
Linux/390
XML
Download
Wap
Internet
VM
MakeThread
[allProperties] [verifHost] [MakeThread]

import java.io.*;
import java.util.*;
import java.text.*;


public class MakeThread implements Runnable {

  public static void main(String args[]) throws Exception {
   int thread_number;
   if ((args.length!=1)) {
       System.out.println("Syntax:");
       System.out.println(" MakeThread thread_number");
       System.out.println("   where");
       System.out.println("   thread_number is the number of threads to be started in parallel");
     return;
   }
   else {
       try {
               thread_number=Integer.parseInt(args[0]);
       }
       catch (Exception e)      {
               System.out.println("Thread number : "+args[0]+" can not be converted to integer.");
           return;
       }
     MakeThread w = new MakeThread();
     w.go(thread_number);
   }
  }

  public void go(int tnum) throws Exception {
   int i;
   for(i=0;i<tnum;i++) {
     Thread t1 = new Thread(this,"Thread number "+i);
     t1.start();
   }
  }

  public void run() {
   String myname = Thread.currentThread().getName();
   try {
       System.out.println(myname + " started. Sleeping for 10 seconds...");
       Thread.sleep(10000);
       System.out.println(myname + " ends.");
   }
   catch (Exception e) {
       e.printStackTrace();
   }
  }
}