What is a thread?
A thread is a program’s path of execution.
What is the difference between process and thread?
A thread is a separate path of execution in a program. A Process is a program in execution.
What is a daemon thread?
A thread that works in the background to support the runtime environment is called a daemon thread. For example, the clock handler thread is a daemon thread.
Explain different ways of implementing threads?
Two ways of implementing threads are implementing Runnable interface or by inheriting from Thread class.
How does multithreading take place on a computer with a single CPU?
The operating system's task scheduler allocates execution time to multiple tasks. By quickly switching between executing tasks, it creates the impression that tasks execute sequentially.
What invokes a thread's run() method?
After a thread is started, via its start() of the Thread class, the JVM invokes the thread's run() when the thread is initially executed.
What are the high-level thread states?
The high-level thread states are ready, running, waiting and dead.
What is deadlock?
When two threads are waiting for each other and can’t proceed until the first thread obtains a lock on the other thread or vice versa, the program is said to be in a deadlock.
What is the purpose of the wait(), notify(), and notifyAll() methods?
The wait(), notify() and notifyAll() methods are used to provide an efficient way for thread inter-communication.
What are some ways in which a thread can enter the waiting state?
1.By invoking sleep()
2.By blocking on I/O
3.By unsuccessfully attempting to acquire an object’s lock
4.By invoking an object’s wait() method
5.By invoking its suspend()
What is the difference between yielding and sleeping?
When a task invokes its yield(), it returns to the ready state, either from waiting, running or after its creation. When a task invokes its sleep(), it returns to the waiting state from a running state.
What state does a thread enter when it terminates its processing?
A thread enters the dead state, when it terminates its processing.
Is there a separate stack for each thread in Java?
Yes, every thread maintains its own separate stack, called RuntimeStack, however they share the same memory.
What do you understand by Synchronization?
Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access one resource at a time. In non synchronized multithreaded application, it is possible for one thread to modify a shared object while another thread is in the process of using or updating the object's value. Synchronization prevents such type of data corruption.
E.g. Synchronizing a function:
public synchronized void Method1 () {
// Appropriate method-related code.
}
E.g. Synchronizing a block of code inside a function:
public myFunction (){
synchronized (this) {
// Synchronized code here.
}
}
what is a transient variable?
A transient variable is a variable that may not be serialized. Transient instance fields are neither saved nor restored by the standard serialisation mechanism. You have to handle restoring them yourself.
Wednesday, September 26, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment