// returns the number of threads currently running
Thread.activeCount()
// returns the name of the current thread
Thread.currentThread().getName()
// sets the name of the current thread
Thread.currentThread().setName("new Name")
// returns the prioprity of the thread,
// the higher the number the higher the priority
// min: 1, max: 10
Thread.currentThread().getPriority()
// sets the priority
Thread.currentThread().setPriority(10)
// checks if the thread is alive
Thread.isAlive();
// thread stops execution for 1000ms
// note needs an exception
Thread.sleep(1000);
// ----- inherit method -----
// better because it is quicker
// put code into run
public class NewThread extends Thread {
@Override
void run() {
...
}
}
// init class
NewThread t1 = new NewThread();
// ----- interface method -----
// better because you can still extend
// put code into run
public class NewRunnable implements Runnable {
@Override
public void run() {
...
}
}
// init class
NewRunnable r1 = new NewRunnable();
Thread t2 = new Thread(r1);
// starts thread execution of run
Thread.start()
// thread calling method will wait until thread terminates
Thread.join()
// thread calling method will wait until termination or for 1 second
Thread.join(1000)
// thread that is low priority
// does garbage collection
// checks if thread is a deamon
Thread.isDeamon();
// sets thread to deamon or not
Thread.setDeamon(true);