Yes, the 'start()' method can be overridden. But it should not be overridden as it's implementation in thread class has the code to create a new executable thread and is specialized.
The methods are as follows:
public static void sleep(long millis) throws InterruptedException
public static void yield()
public final void join() throws InterruptedException
public final void setPriority(int priority)
public final void wait() throws InterruptedException
public final void notify()
public final void notifyAll()
The methods are:
public final void wait() throws Interrupted exception
public final void notify()
public final void notifyAll()
Methods which are mainly used are as follows:
public static void sleep(long millis) throws Interrupted exception
public static void yield() public final void join() throws Interrupted exception
public final void setPriority(int priority)
public void start()
public void interrupt()
public final void join()
public void run()
public void resume()
Following are the methods:
notify()
join()
sleep()
yield()
wait().
Yes, each thread has its own call stack.
In the below example t1 and t3 will have the same stack and t2 will have its own independent stack.
Thread t1 = new Thread();
Thread t2 = new Thread();
Thread t3 = t1;
In a multi-threaded environment thread starvation occurs if a low priority thread is not able to run or get a lock on the resource because of presence of many high priority threads. This is mainly possible by setting thread priorities inappropriately.
ThreadLocal is a class. If a variable is declared as threadLocal then each thread will have a its own copy of variable and would not interfere with the other's thread copy. Typical scenario to use this would be giving JDBC connection to each thread so that there is no conflict.
ThreadLocal_JBK class by JAVA API
public class ThreadLocal_JBK
{
public Object get();
public void set(Object newValue);
public Object initialValue();
}
Implementation of ThreadLocal
public class ConnectionDispenser_JBK
{
private static class ThreadLocalConnection_JBK extends ThreadLocal_JBK
{
public Object initialValue()
{
return DriverManager.getConnection(ConfigurationSingleton.getDbUrl());
}
}
private static ThreadLocalConnection_JBK conn = new ThreadLocalConnection_JBK();
public static Connection getConnection()
{
return (Connection) conn.get();
}
}