static Thread
currentThread()
Returns a reference to the currently executing thread object.
long
getId()
Returns the identifier of the thread.
String
getName()
Returns the name of the thread.
int
getPriority()
Returns the priority of the thread.
Thread.State
getState()
Returns the state of the thread.
static void
sleep(long millis)
Lets the currently executing thread hibernate (suspends execution) within the specified number of milliseconds, which is affected by the accuracy and accuracy of the system timer and scheduler.
static void
sleep(long millis, int nanos)
Allows the currently executing thread to hibernate (suspend execution) within the specified number of milliseconds plus the specified number of nanoseconds, which is affected by the accuracy and accuracy of the system timer and scheduler.
/** * */ PackageCom.train; Public classmthreadtest{ Public Static voidMain (string[] args) {Ticketseller tser1=NewTicketseller ("Tser1"); Ticketseller Tser2=NewTicketseller ("Tser2"); Ticketseller Tser3=NewTicketseller ("Tser3"); Ticketseller Tser4=NewTicketseller ("Tser4"); Tser1.start (); Tser2.start (); Tser3.start (); Tser4.start (); }} classTicketsellerextendsthread{Private Static intTicknum = 100; Ticketseller (String name) {Super(name); } //Override Public voidrun () {Selltick (1); } Public voidSelltick (intnum) { if(Ticknum > 0) {System.out.println ( This. GetName () + "sells" +ticknum--); }Else{System.out.println ("Sell out!"); } System.out.println ("Current ticket number is" +ticknum); }}
Java Basics-Multi-threading-ticketing