For BE/B.Tech/BCA/MCA/ME/M.Tech Major/Minor Project for CS/IT branch at minimum price Text Message @ 9424820157

Threads Interview Questions in Java

Threads Interview Questions in Java




(1) What is Thread?
Thread is a class.it is a lightweight process for performing a certain task

(2) Why Thread is light weighted?
 Since it shares resources that’s why it is light weighted.

(3) What is life cycle of Thread?
Born => run => blocked => dead

(4) How two threads communicate with each other?
They communicate with the help of shared memory area

(5) How two process communicate with each other?
 With the help of environment variables

(6) What are Daemon Threads?
Daemon threads are background threads that support the other threads running in the same process.Ex: garbage collector

(7) What are green threads?
 The Threads scheduled by JVM are green threads

(8) What are native threads?
 Threads scheduled by operating system are native threads.

(9) What is deadlock condition?
 Deadlock is condition  when two or more threads waiting for   each other to release the lock in a circular chain

(10) How many methods are in Thread class?
start()
sleep()
getPriority()
setPriority()
join()
stop()
yield()
isDaemon()

(11) What is start()?
 It is used to start a thread

(12) What is stop()?
It is used to stop a thread

(13) What is sleep()?
It is used for wait the operation for some milliseconds and nanoseconds.

(14) What is starvation and livelock?
Starvation and livelock both are same.it happens when a thread wait for a long time for execution.it occurs in non-preemptive scheduling.

(15) What is method or block synchronization?
When synchronization is applied for block than it is block synchronization and when applied for method than it is method synchronization

(16) What is monitor key?
Monitor key is lock. When one thread occupies the monitor key than other threads must wait until that thread exit from monitor.

(17) How many monitor keys are assigned for a class?
(a) one for static method 
(b) one for instance method

(18) What is synchronization?
It ensure that only one key executes at a time.

(19) What is racing condition?
When two or more threads trying to access the same resource concurrently is called racing condition.

(20) How do you solve racing condition?
With the help of synchronization

(21) How many types of synchronization?
There are 3 types of synchronization :
(a)  block synchronization 
(b) method synchronization 
(c) static synchronization 

(22) In which package thread class is found?
 java.lang package

(23) What is work of Daemon thread?
It supports the other main threads. Example System.gc()

(24) What is monitor?
Monitor is object which contains synchronized code in it.

(25) What is process?
Execution of a program is process. it is heavyweight and contains at least one thread

(26) When daemon threads get dead?
When jvm get stop

(27) What is scheduling?
Scheduling is a process used to determine how threads are allocated cpu time.

(28) What is preemptive scheduling?
Thread scheduler preempts the running thread and allow different thread to execute.

(29) What is non-preemptive scheduling?
The thread scheduler never interrupts the running thread

(30) What is time slicing scheduling?
In time slicing scheduling, scheduler allocates a period of time that each thread can use the CPU after completion of time the thread get exit.

(31) How many Thread classes are there?
Thread,ThreadGroup,RunTime

(32) Difference between stop() and run()?
In run method, some logical code is present which  determines the operation of thread.
Stop() terminates the running thread.

(33) How do we find that our program is deadlocked?
By tracking thread dump using kill-3, using Jconsole or visual vm.

(34) What is notify()?
It resumes the thread in running state that is in wait state.

(35) What is notifyAll()?
It resumes all the threads in running state that are in wait  state.

(36) What is join()?
Calling thread does not release the monitor, for example t2 calls t1.join() then t2 will wait and T1 does not release the lock until it gets finished completely.

(37) What is the difference between process and thread?
                             
Process
Thread
Process contains threads
Threads do not contain process
Processes are heavy weighted
Threads are light weighted
Process communicates by environment variables
Threads communicate by shared memory area






No comments:

Post a Comment



Please go through below tutorials:


Mule 4 Tutorials

DEPLOY TO CLOUDHUB C4E CLIENT ID ENFORCEMENT CUSTOM POLICY RABBIT MQ INTEGRATION
XML TO JSON WEBSERVICE CONSUMER VM CONNECTOR VALIDATION UNTIL SUCCESSFUL
SUB FLOW SET & REMOVE VARIABLE TRANSACTION ID SCATTER GATHER ROUND ROBIN
CONSUME REST WEBSERVICE CRUD OPERATIONS PARSE TEMPLATE OBJECT TO JSON LOAD STATIC RESOURCE
JSON TO XML INVOKE IDEMPOTENT FILTER FOR EACH FLAT TO JSON
FIXWIDTH TO JSON FIRST SUCCESSFUL FILE OPERATIONS EXECUTE ERROR HANDLING
EMAIL FUNCTIONALITY DYNAMIC EVALUATE CUSTOM BUSINESS EVENT CSV TO JSON COPYBOOK TO JSON
CHOICE ASYNC

Widely used Connectors in Mule 3

CMIS JETTY VM CONNECTOR SALESFORCE POP3
JMS TCP/IP WEBSERVICE CONSUMER QUARTZ MONGO DB
FILE CONNECTOR DATABASE CONNECTOR


Widely used Scopes in Mule 3

SUB FLOW REQUEST REPLY PROCESSOR CHAIN FOR EACH CACHE
ASYNC TCP/IP COMPOSITE SOURCE POLL UNTIL SUCCESSFUL
TRANSACTIONAL FLOW

Widely used Components in Mule 3

EXPRESSION CXF SCRIPT RUBY PYTHON
JAVASCRIPT JAVA INVOKE CUSTOM BUSINESS EVENT GROOVY
ECHO LOGGER


Widely used Transformers in Mule 3

MONGO DB XSLT TRANSFORMER REFERENCE SCRIPT RUBY
PYTHON MESSAGE PROPERTIES JAVA TRANSFORMER GZIP COMPRESS/UNCOMPRESS GROOVY
EXPRESSION DOM TO XML STRING VALIDATION COMBINE COLLECTIONS BYTE ARRAY TO STRING
ATTACHMENT TRANSFORMER FILE TO STRING XML TO DOM APPEND STRING JAVASCRIPT
JSON TO JAVA COPYBOOK TO JSON MAP TO JSON JSON TO XML FLATFILE TO JSON
FIXWIDTH TO JSON CSV TO JSON


Widely used Filters in Mule 3

WILDCARD SCHEMA VALIDATION REGEX PAYLOAD OR
NOT MESSAGE PROPERTY MESSAGE IDEMPOTENT FILTER REFERNCE
EXPRESSION EXCEPTION CUSTOM AND


Exception Strategy in Mule 3

REFERENCE EXCEPTION STRATEGY CUSTOM EXCEPTION STRATEGY CHOICE EXCEPTION STRATEGY CATCH EXCEPTION STRATEGY GLOBAL EXCEPTION STRATEGY


Flow Control in Mule 3

CHOICE COLLECTION AGGREGATOR COLLECTION SPLITTER CUSTOM AGGREGATOR FIRST SUCCESSFUL
MESSAGE CHUNK AGGREGATOR MESSAGE CHUNK SPLITTER RESEQUENCER ROUND ROBIN SOAP ROUTER