Java Reference
In-Depth Information
1. Create a file called UseMain.java .
2. To access the main thread, you must obtain a Thread object that refers to it. You do
this by calling the currentThread( ) method, which is a static member of Thread .
Its general form is shown here:
static Thread currentThread( )
This method returns a reference to the thread in which it is called. Therefore, if you
call currentThread( ) while execution is inside the main thread, you will obtain a
reference to the main thread. Once you have this reference, you can control the main
thread just like any other thread.
3. Enter the following program into the file. It obtains a reference to the main thread,
and then gets and sets the main thread's name and priority.
Search WWH ::




Custom Search