CORE API / CATATAN</>↗Core API07 Nov 2010
To get the currently executing thread, use the static currentThread() method of the Thread class. This method returns a reference of the currently executing thread object. package org.kodejava.lang; public class GetCurrentThreadDemo { public static void main(String[] args) { // Get the currently executing thread object Thread thread = Thread.currentThread(); System.out.println("Id : " + thread.getId()); System.out.println("Name […]
CORE API / CATATAN</>↗Core API07 Nov 2010
You can assign a name to thread instance by using the setName() method and get the name of the thread using the getName() method. The naming support is also available as a constructor of the Thread class such as Thread(String name) and Thread(Runnable target, String name). package org.kodejava.lang; public class ThreadNameDemo extends Thread { public […]
CORE API / CATATAN</>↗Core API07 Nov 2010
A thread is alive or running if it has been started and has not yet died. To check whether a thread is alive use the isAlive() method of Thread class. It will return true if this thread is alive, otherwise return false. package org.kodejava.lang; public class ThreadAliveDemo implements Runnable { public static void main(String[] args) […]
CORE API / CATATAN</>↗Core API06 Nov 2010
You can test if a thread is a daemon thread or a user thread by calling the isDaemon() method of the Thread class. If it returns true then the thread is a daemon thread, otherwise it is a user thread. package org.kodejava.lang; public class ThreadCheckDaemon implements Runnable { public static void main(String[] args) { Thread […]
CORE API / CATATAN</>↗Core API06 Nov 2010
A daemon thread is simply a background thread that is subordinate to the thread that creates it, so when the thread that created the daemon thread ends, the daemon thread dies with it. A thread that is not a daemon thread is called a user thread. To create a daemon thread, call setDaemon() method with […]
CORE API / CATATAN</>↗Core API05 Nov 2010
Here is another example that use the Thread.sleep() method. In the example we create two instances of the ThreadSleepAnotherDemo, we give each thread a name and the sleep interval so that we can see how to thread execution. package org.kodejava.lang; import java.util.Calendar; public class ThreadSleep implements Runnable { private final String threadName; private final long […]