Page 153 - CITS - CSA - TP (Volume 2) - Hindi
P. 153
कं ूटर सॉ वेयर ए ीके शन - CITS
अ ास 101 : ेड बनाएं और चलाएं (Create and run a thread)
उ े
इस अ ास के अंत म आप यह कर सक गे
• JAVA म ेड्स के िनमा ण और िन ादन को जानना
• सुपर ास और सब ास का उपयोग करके JAVA ो ाम डेवलप करना।
आव कताएं (Requirements)
उपकरण/साम ी (Tools/Materials)
• िवंडोज OS वाला PC/लैपटॉप
• SDK सॉ वेयर
• टे एिडटर (िवजुअल ू िडयो/सबलाइम/नोटपैड)
ि या (Procedure)
जावा म , ेड िकसी ो ाम के भीतर िन ादन के िसंगल लो का ितिनिध करता है। ेड्स ो ाम को एक साथ कई काय करने की अनुमित देते ह ,
िजससे कोड के म ी पीस को एक साथ िन ािदत करना संभव हो जाता है।
टा 1: ेड बनाना और सि य करना
public class MyThread1
{
// Main method
public static void main(String argvs[])
{
// creating an object of the Thread class using the constructor Thread(String name)
Thread t= new Thread(“My first thread”);
// the start() method moves the thread to the active state
t.start();
// getting the thread name by invoking the getName() method
String str = t.getName();
System.out.println(str);
}
}
ीकरण:
चरण 1: उपरो कोड डेवलप कर
• यह कोड MyThread1 नामक एक ास को प रभािषत करता है।
• मु िविध ो ाम का वेश िबंदु है।
139

