Java J2ee Struts Hibernate Spring Interview Questions Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4    Next

1. What is a green thread ?

Native threads can switch between threads preemptively, switching control from a running thread to a non-running thread at any time. Green threads only switch when control is explicitly given up by a thread (Thread.yield(), Object.wait(), etc.) or a thread performs a blocking operation (read(), etc.). On multi-CPU machines, native threads can run more than one thread simultaneously by assigning different threads to different CPUs. Green threads run on only one CPU. Native threads create the appearance that many Java processes are running: each thread takes up its own entry in the process table. One clue that these are all threads of the same process is that the memory size is identical for all the threads - they are all using the same memory. Unfortunately, this behavior limits the scalability of Java on Linux. The process table is not infinitely large, and processes can only create a limited number of threads before running out of system resources or hitting configured limits.

2. What are daemon threads?

In java we have two type of Threads : Daemon Thread and User Threads. Generally all threads created by programmer are user thread (unless you specify it to be daemon or your parent thread is a daemon thread). User thread are generally meant to run our programm code. JVM doesn't terminates unless all the user thread terminate.

On the other hand we have Daemon threads. Typically these threads are service provider threads. They should not be used to run your program code but some system code. These thread run paralley to your code but survive on the mercy of the JVM. When JVM finds no user threads it stops and all daemon thread terminate instantly. Thus one should never rely on daemon code to perform any program code.

For better understanding consider a well known example of Daemon thread : Java garbage collector. Garbage collector runs as a daemon thread to recalim any unused memory. When all user threads terminates, JVM may stop and garbage collector also terminates instantly.

3. What type of threads are there in java ?

two types of threads are there in java, they are background threads or system threads or service threads or daemon threads and user threads.

Daemon thread is one which executes at background and wastes all the resources. 

4. At what situation you will go to implement your application as threads ?

In all situations try to utilize multithreading.
if you have single core server you will not get multithreading advantage.
If you have 4 core / 8 core processors then,
Identify all the sequential and concurrent computations.
based on number of cores, create those many threads and run.

mostly in heavy batch processing implement multi-threading.

5. What is the difference between Thread and a Process

Threads run inside process and they share data. One process can have multiple threads, if the process is killed all the threads inside it are killed, they dont share data

Advantages of Thread
Threads minimize the context switching time. Use of threads provides concurrency within a process. Efficient communication. It is more economical to create and context switch threads.

6. What is synchronization

Synchronization is a technique to control the access of multiple threads to shared resources. Synchronization stops multithreading. With synchronization , at a time only one thread will be able to access a shared resource.
Synchronization is a process of controlling the access of shared resources by the multiple threads. 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. The best example to learn this concept is to understand Producer Consumer problem.

7. Why threads block or enters to waiting state on I/O?

Threads enters to waiting state or block on I/O because other threads can execute while the I/O operations are performed.

8. Why do threads block on I/O ?

Threads block on i/o (that is enters the waiting state) so that other threads may execute while the I/O operation is performed.

9. If all the threads in a Servlet are hanged. How do you come-out or debug from this situation ?

By Monitor thread .

10. What is the main disadvantage of threads ?

The main disadvantage of thread is that we need to synchronize the object while using the thread-deadlocks, data races, starvation are the main issues we need to consider-performance will be low because of synchronization.

Java J2ee Struts Hibernate Spring Interview Questions
1 2 3 4    Next
Menu - - Java J2ee Struts Spring Hibernate Interview Questions - A home for your website
Ads By Google