A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads. There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.
Is it helpful?
Add CommentView Comments
Ques 142. What is a thread?
Thread is a block of code which can execute concurrently with other threads in the JVM.
Is it helpful?
Add CommentView Comments
Ques 143. What is the algorithm used in Thread scheduling?
Ques 145. What are the ways in which you can instantiate a thread?
Using Thread class By implementing the Runnable interface and giving that handle to the Thread class.
class RunnableThread implements Runnable {
Thread runner;
public RunnableThread() {
}
public RunnableThread(String threadName) {
runner = new Thread(this, threadName); // (1) Create a new thread.
System.out.println(runner.getName());
runner.start(); // (2) Start the thread.
}
public void run() {
//Display info about this particular thread
System.out.println(Thread.currentThread());
}
}