» נושאי לימוד
» נושאי לימוד
יום שני 29 באפריל 2024
תוכנית rum
דף ראשי  מתקדמים  Treads of control  סקירה כללית  תוכנית rum גרסה להדפסה

/*File Thread01.java  Copyright 1997, R.G.Baldwin
Illustrates instantiation and running of threads using the
runnable interface instead of extending the Thread class.
Tested using JDK 1.1.3 under Win95.
The output is:
Thread[threadA,5,main]
Thread[threadB,5,main]
Thread[main,5,main]
**********************************************************/
class Thread01{
static public void main(String[] args){
//Instantiate two new thread objects
Thread myThreadA =
new Thread(new MyThread(),"threadA");
Thread myThreadB =
new Thread(new MyThread(),"threadB");
//Start them running
myThreadA.start();
myThreadB.start();
try{
//delay for one second
Thread.currentThread().sleep(1000);
}catch(InterruptedException e){}
//Display info about the main thread
System.out.println(Thread.currentThread());
}//end main
}//end class Thread01
//=======================================================//
class DoNothing{
//This class exists only to be inherited by the MyThread
// class to prevent that class from being able to inherit
// the Thread class, thus requiring it to implement the
// Runnable interface instead.}
//end class DoNothing
//=======================================================//
class MyThread extends DoNothing implements Runnable{
public void run(){
//Display info about this particular thread
System.out.println(Thread.currentThread());

}//end run
}//end class MyThread

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 11-10-03 / 11:12  נוצר ע"י רונית רייכמן  בתאריך 
 סקירה כללית - הקודםהבא - תוכנית Thread 
תגובות הקוראים    תגובות  -  0
דרכונט
מהי מערכת הדרכונט?
אינך מחובר, להתחברות:
דוא"ל
ססמא
נושאי לימוד
חיפוש  |  לא פועל
משלנו  |  לא פועל
גולשים מקוונים: 4