Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
59 views
Java Multithreading and Concurrency Interview
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java Multithreading and Concurrency Interview For Later
Download
Save
Save Java Multithreading and Concurrency Interview For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
59 views
Java Multithreading and Concurrency Interview
Uploaded by
Ayalkibet Abriham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java Multithreading and Concurrency Interview For Later
Carousel Previous
Carousel Next
Save
Save Java Multithreading and Concurrency Interview For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 31
Search
Fullscreen
‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint Home aterview Questions ava sa Pythor Java Angula SCROLL TO TOP nps:iiwwjavatpoin comijava-multhreading-nlerview-questions vat‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint Java Multithreading and Concurrency Interview Questions Multithreading and Synchronization are considered as the typical chapter in java programming. In game development companies, multithreading related interview questions are asked mostly. A list of frequently asked java multithreading and concurrency interview questions is given below. Multithreading Interview Questions 1) What is multithreading? Multithreading is a process of executing multiple threads simultaneously, Multithreading is used to obtain the multitasking, It consumes less memory and gives the fast and efficient performance. Its main advantages are © Threads share the same address space. © The thread is lightweight. © The cost of communication between the processes is low. More details. 2) What is the thread? A thread is a lightweight subprocess. It is a separate path of execution because each thread runs in a different stack frame. A process may contain multiple threads. Threads share the process resources, but still, they execute independently. More details. 3) Differentiate between process and thread? There are the following differences between the process and thread. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 2st‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint © A Program in the execution is called the process whereas; A thread is a subset of the process © Processes are independent whereas threads are the subset of process. © Process have different address space in memory, while threads contain a shared address space. © Context switching is faster between the threads as compared to processes. © Inter-process communication is slower and expensive than inter-thread communication © Any change in Parent process doesn't affect the child process whereas changes in parent thread can affect the child thread tps: javatpoint comjava-mulithreadinginlrviw-questions ist2122022, 11:53 PM Java Multthreacing interview Questions (2028) javatpoint Crtee) Dre) os 4) What do you understand by inter-thread communication? © The process of communication between synchronized threads is termed as inter-thread communication. © Inter-thread communication is used to avoid thread polling in Java. © The thread is paused running in its critical section, and another thread is allowed to enter (or lock) in the same critical section to be executed. © Itcan be obtained by wait(, notify(), and notifyAll) methods. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions ast‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint 5) What is the purpose of wait() method in Java? The wait) method is provided by the Object class in Java. This method is used for inter-thread communication in Java. The java.lang.Objectwait() is used to pause the current thread, and wait until another thread does not call the notify() or notifyAll) method. Its syntax is given below. public final void wait() 6) Why must wait() method be called from the synchronized block? We must call the wait method otherwise it will throw java.lang.lllegalMonitorStateException exception. Moreover, we need wait) method for inter-thread communication with notify) and notifyAll. Therefore It must be present in the synchronized block for the proper and correct communication, 7) What are the advantages of multithreading? Multithreading programming has the following advantages © Multithreading allows an application/program to be always reactive for input, even already running with some background tasks © Multithreading allows the faster execution of tasks, as threads execute independently. © Multithreading provides better utilization of cache memory as threads share the common memory resources © Multithreading reduces the number of the required server as one server can execute multiple threads at a time. 8) What are the states in the lifecycle of a Thread? A thread can have one of the following states during its lifetime: 1. New: In this state, a Thread class object is created using a new operator, but the thread is not alive. Thread doesn't start until we call the start() method, 2. Runnable: In this state, the thread is ready to run after calling the start) method. However, the thread is not yet selected by the thread scheduler. 3. Running: In this state, the thread scheduler picks the thread from the ready state, and the thread is running ptosis inlarvew-qumtons set‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint 4, Waiting/Blocked: In this state, a thread is not running but still alive, or it is waiting for the other thread to finish. 5, Dead/Terminated: A thread is in terminated or dead state when the run() method exits, start) § sleep() done, /o complete, lock available, resume(), notify() or notifyAll) OTT Ly Ur § red] sleep(), block on 1/0, wait meen y for lock, suspend(), wait() or stop() a] 9) What is the difference between preemptive scheduling and time slicing? Under preemptive scheduling, the highest priority task executes until it enters the waiting or dead states or a higher priority task comes into existence. Under time slicing, a task executes for a predefined slice of time and then reenters the pool of ready tasks. The scheduler then determines which task should execute next, based on priority and other factors. 10) What is context switching? In Context switching the state of the process (or thread) is stored so that it can be restored and execution can be resumed from the same point later. Context switching enables the multiple processes to share the same CPU. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions eat‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint 11) Differentiate between the Thread class and Runnable interface for creating a Thread? The Thread can be created by using two ways. © By extending the Thread class © By implementing the Runnable interface However, the primary differences between both the ways are given below: © By extending the Thread class, we cannot extend any other class, as Java does not allow multiple inheritances while implementing the Runnable interface; we can also extend other base class(if required). © By extending the Thread class, each of thread creates the unique object and associates with it while implementing the Runnable interface; multiple threads share the same object © Thread class provides various inbuilt methods such as getPriority0, isAlive and many more while the Runnable interface provides a single method, i.e, rund. 12) What does join() method? The join) method waits for a thread to die. In other words, it causes the currently running threads to stop executing until the thread it joins with completes its task. Join method is overloaded in Thread class in the following ways. © public void joinOthrows InterruptedException © public void join(long milliseconds)throws InterruptedException tps: javatpoint comjava-mulithreadinginlrviow-questions 31‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint More details. 13) Describe the purpose and working of sleep() method. The sleep() method in java is used to block a thread for a particular time, which means it pause the execution of a thread for a specific time, There are two methods of doing so. Syntax: © public static void sleep(long milliseconds)throws InterruptedException © public static void sleep(long milliseconds, int nanos)throws InterruptedException Working of sleep() method When we call the sleep() method, it pauses the execution of the current thread for the given time and gives priority to another thread{if available). Moreover, when the waiting time completed then again previous thread changes its state from waiting to runnable and comes in running state, and the whole process works so on till the execution doesn't complete, 14) What is the difference between wait() and sleep() method? wait) sleep 1) The wait method is defined in Object class. The sleep() method is defined in Thread class. 2) The wait() method releases the lock. The sleep() method doesn't release the lock. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions at‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint 15) Is it possible to start a thread twice? No, we cannot restart the thread, as once a thread started and executed, it goes to the Dead state. Therefore, if we try to start a thread twice, it will give a runtimeException "java.langlllegalThreadStateException”. Consider the following example. public class Multithread1 extends Thread { public void rund { try{ System.out printin(“thread is executing NOW...n.")j } catch(Exception e) { } } public static void main (String[] args) { Multithread1 m1= new Multithread1(); m1 -startd; m1 start); Output nps:iiwwjavatpoin comijava-multhreading-nlerview-questions gt‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint thread is executing now. Exception in thread “main” java.lang.IllegalThreadStateException at java. lang. Thread. start (Thread. java: 708) at Multithread1.main(Multithreadi . java:13) More details. 16) Can we call the run() method instead of start()? Yes, calling run() method directly is valid, but it will not work as a thread instead it will work as a normal object. There will not be context-switching between the threads. When we call the start, method, it internally calls the run method, which creates a new stack for a thread while directly calling the run( will not create a new stack. More details. 17) What about the daemon threads? The daemon threads are the low priority threads that provide the background support and services to the user threads. Daemon thread gets automatically terminated by the JVM if the program remains with the daemon thread only, and all other user threads are ended/died. There are two methods for daemon thread available in the Thread class: © public void setDaemon(boolean status): It used to mark the thread daemon thread or a user thread. © public boolean isDaemon(): It checks the thread is daemon or not. More details. 18)Can we make the user thread as daemon thread if the thread is started? No, if you do so, it will throw IllegalThreadStateException. Therefore, we can only create a daemon thread before starting the thread. class Testdaemon1 extends Thread{ ‘nps:iiwwjavatpoin comijava-multhreading-nlerview-questions ro‘222m, 1159 PM Java Multveading new Question (2023) avatpint public void rung System.out printin(’Running thread is daemon. ) public static void main (Stringl] args) ( Testdaemont td= new Testdaemon10; ‘td.start0; setDaemon(true);// It will throw the exception: td. Output Running thread is daemon... Exception in thread “main” java.lang.IllegalThreadStateException java. lang. Thread. setDaemon(Thread. java:1359) at Testdaemon1.main(Testdaemoni. java:8) More details. 19)What is shutdown hook? The shutdown hook is a thread that is invoked implicitly before JVM shuts down. So we can use it to perform clean up the resource or save the state when JVM shuts down normally or abruptly. We can add shutdown hook by using the following method: public void addShutdownHook(Thread hook)(} Runtime r.addShutdownHook(new MyThread()); {untime.getRuntime(); Some important points about shutdown hooks are © Shutdown hooks initialized but can only be started when JVM shutdown occurred. © Shutdown hooks are more reliable than the finalizer) because there are very fewer chances that shutdown hooks not run, ©. The shutdown hook can be stopped by calling the halt(int) method of Runtime class. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions nat‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint More details. 20)When should we interrupt a thread? We should interrupt a thread when we want to break out the sleep or wait state of a thread. We can interrupt a thread by calling the interrupt throwing the InterruptedException, More details. 21) What is the synchronization? Synchronization is the capability to control the access of multiple threads to any shared resource, It is used: 1. To prevent thread interference. 2. To prevent consistency problem. When the multiple threads try to do the same task, there is a possibility of an erroneous result, hence to remove this issue, Java uses the process of synchronization which allows only one thread to be executed at a time. Synchronization can be achieved in three ways: © by the synchronized method © by synchronized block © by static synchronization Syntax for synchronized block 1 |nps:iiwwjavatpoin comijava-multhreading-nlerview-questions vast‘222m, 1159 PM Java Muloveading nteiew Question (2023) avatpint synchronized(object reference expression) { I/code block More details. 22) What is the purpose of the Synchronized block? The Synchronized block can be used to perform synchronization on any specific resource of the method. Only one thread at a time can execute on a particular resource, and all other threads which attempt to enter the synchronized block are blocked. © Synchronized block is used to lock an object for any shared resource © The scope of the synchronized block is limited to the block on which, it is applied. Its scope is smaller than a method, More details. 23)Can Java object be locked down for exclusive use by a given thread? Yes. You can lock an object by putting it in a "synchronized block. The locked object is inaccessible to any thread other than the one that explicitly claimed it. 24) What is static synchronization? If you make any static method as synchronized, the lock will be on the class not on the object. If we use the synchronized keyword before a method so it will lock the object (one thread can access an object at a time) but if we use static synchronized so it will lock a class (one thread can access a class at a time). More details. 25)What is the difference between notify() and notifyAll()? The notify() is used to unblock one waiting thread whereas notifyAll) method is used to unblock all the threads in waiting state. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions rat‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint 26)What is the deadlock? Deadlock is a situation in which every thread is waiting for a resource which is held by some other waiting thread. In this situation, Neither of the thread executes nor it gets the chance to be executed. Instead, there exists a universal waiting state among all the threads. Deadlock is a very complicated situation which can break our code at runtime. More details. 27) How to detect a deadlock condition? How can it be avoided? We can detect the deadlock condition by running the code on cmd and collecting the Thread Dump, and if any deadlock is present in the code, then a message will appear on cmd. Ways to avoid the deadlock condition in Java: © Avoid Nested lock: Nested lock is the common reason for deadlock as deadlock occurs when we provide locks to various threads so we should give one lock to only one thread at some particular time. © Avoid unnecessary locks: we must avoid the locks which are not required. © Using thread join: Thread join helps to wait for a thread until another thread doesn't finish its execution so we can avoid deadlock by maximum use of join method. 28) What is Thread Scheduler in java? In Java, when we create the threads, they are supervised with the help of a Thread Scheduler, which is the part of JVM. Thread scheduler is only responsible for deciding which thread should be executed. Thread scheduler uses two mechanisms for scheduling the threads: Preemptive and Time Slicing. Java thread scheduler also works for deciding the following for a thread: © Itselects the priority of the thread, © Itdetermines the waiting time for a thread © It checks the Nature of thread nps:iiwwjavatpoin comijava-multhreading-nlerview-questions vais‘222m, 1159 OM Jove Mulvtveading nteiew Question (2023) avatpint 29) Does each thread have its stack in multithreaded programming? Yes, in multithreaded programming every thread maintains its own or separate stack area in memory due to which every thread is independent of each other. 30) How is the safety of a thread achieved? If a method or class object can be used by multiple threads at a time without any race condition, then the class is thread-safe, Thread safety is used to make a program safe to use in multithreaded programming. It can be achieved by the following ways: ° Synchronization ° Using Volatile keyword ° Using a lock based mechanism ° Use of atomic wrapper classes 31) What is race-condition? A Race condition is a problem which occurs in the multithreaded programming when various threads execute simultaneously accessing a shared resource at the same time. The proper use of synchronization can avoid the Race condition, 32) What is the volatile keyword in java? Volatile keyword is used in multithreaded programming to achieve the thread safety, as a change in one volatile variable is visible to all other threads so one variable can be used by one thread at a time. 33) What do you understand by thread pool? © Java Thread pool represents a group of worker threads, which are waiting for the task to be allocated, © Threads in the thread pool are supervised by the service provider which pulls one thread from the pool and assign a job to it. © After completion of the given task, thread again came to the thread pool. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 1691‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint © The size of the thread pool depends on the total number of threads kept at reserve for execution. The advantages of the thread pool are © Using a thread pool, performance can be enhanced, © Using a thread pool, better system stability can occur. Concurrency Interview Questions 34) What are the main components of concurrency API? Concurrency API can be developed using the class and interfaces of java.util. Concurrent package. There are the following classes and interfaces in java.util, Concurrent package © Executor © FarkloinPool © ExecutorService © ScheduledExecutorService © Future © TimeUnit(Enum) © CountDownLatch © CyclicBarrier © Semaphore © ThreadFactory © BlockingQueue © DelayQueue © Locks © Phaser nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 1691‘222m, 1159 OM Java Multveading nti Question (2023) avatpint 35) What is the Executor interface in Concurrency API in Java? The Executor Interface provided by the package java.util.oncurrent is the simple interface used to execute the new task. The execute) method of Executor interface is used to execute some given command. The syntax of the execute) method is given below. void execute(Runnable command) Consider the following example: import java.util.concurrent Executor; import java.util concurrent Executors, import java.util.concurrent.ThreadPoolExecutor; import java.util concurrent. TimeUnit; public class TestThread { public static void main(final String{] arguments) throws InterruptedException { Executor e = Executors.newCachedThreadPool(); e.execute(new Thread()); ThreadPoolExecutor pool = (ThreadPoolExecutor)e; poolshutdownd; static class Thread implements Runnable ( public void rund { try ( Long duration = (long) (Math.random) * 5); System.out printin(’Running Thread!"); TimeUnit SECONDS sleep(duration); System.out printin("Thread Completed”); } catch (InterruptedException ex) { ex.printStackTrace(; |nps:iiwwjavatpoin comijava-multhreading-nlerview-questions wristsana, 159M Jove Muted teniew Qesons (2023) jvtpoht [Pp Output Running Thread! Thread Completed 36) What is BlockingQueue? The java.util.concurrentBlockingQueue is the subinterface of Queue that supports the operations such as waiting for the space availability before inserting a new value or waiting for the queue to become non-empty before retrieving an element from it. Consider the following example. import java.util Random; import java.utilconcurrentArrayBlockingQueue; import java.util. concurrent BlockingQueue; public class TestThread { public static void main(final String{] arguments) throws InterruptedException { BlockingQueue
queue = new ArrayBlockingQueue
(10); Insert i = new Insert(queue); Retrieve r = new Retrieve(queue); new Thread(i) start); new Thread(r) start); Thread sleep(2000); static class Insert implements Runnable ( |nps:iiwwjavatpoin.comijava-multhreading-nlerview-questions vast12122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint private BlockingQueue
queue; public Insert(BlockingQueue queue) { this.queue = queue; @Override public void rund { Random random = new Random; try int result = random.nextint(200); Thread.sleep(1000); queue put(result); System.out printin(’Added: " + result); result = random.nextint(10); Thread.sleep(1000); queue.put(result); System.out printin(’Added: * + result); result = random.nextlnt(50); Thread.sleep(1000); queue.put(result); System.out printin("Added: * + result); } catch (InterruptedException e) e.printStackTrace(; static class Retrieve plements Runnable ( private BlockingQueue
queue; nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 93‘222m, 1159 PM Java Multveading nti Question (2023) avatpint public Retrieve(BlockingQueue queue) { this.queue = queue; @Override public void rund { try System. out printin(’Removed: + queue.take()); System.out printin("Removed: " + queuetake(); System.out printin(‘Removed: * + queue.take(); } catch (InterruptedException e) ( e-printStackTrace(: Output Added: 96 Removed Added: 8 Removed: 8 Added: 5 Removed: 5 37) How to implement producer-consumer problem by using BlockingQueue? The producer-consumer problem can be solved by using BlockingQueue in the following way. import java.util. concurrent BlockingQueue; |nps:iiwwjavatpoin.comijava-multhreading-nlerview-questions 20191‘222m, 1159 PM Jove Mulvtveading nteiew Question (2023) avatpint import java.util. concurrent LinkedBlockingQueue; import java.util.logging Level; import java.utillogging Logger, public class ProducerConsumerProblem { public static void main(String args()){ //Creating shared object BlockingQueue sharedQueue = new LinkedBlockingQueue(; //Creating Producer and Consumer Thread Thread prod = new Thread(new Producer(sharedQueue)); Thread cons = new Thread(new Consumer(sharedQueue)); 1/Starting producer and Consumer thread prod.start(); cons.start(); } //Producer Class in java class Producer implements Runnable { private final BlockingQueue sharedQueue; public Producer(BlockingQueue sharedQueue) { this sharedQueue = sharedQueue; @Override public void rund { for(int i=0; 1< 10; i++){ try( System out.printin( "Produced: " + i); sharedQueue putt); |nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 2a‘222m, 1159 PM Jove Mulvtveading nteiew Question (2023) avatpint } catch (InterruptedException ex) { Logger.getLogger(Producer.class.getName().log(Level SEVERE, null, ex); //Consumer Class in Java class Consumer implements Runnable( private final BlockingQueue sharedQueue; public Consumer (BlockingQueue sharedQueue) ( this.sharedQueue = sharedQueue; @Override public void rund { while(true){ try ( System.out.printin(’Consumed: “+ sharedQueue.take0); } catch (InterruptedException ex) { Logger.getLogger(Consumer.class.getName()log(Level SEVERE, null, ex); } ) Output Produced: @ Produced: 1 Produced: 2 |nps:iiwwjavatpoin comijava-multhreading-nlerview-questions a112122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint Produced: 3 Produced: 4 Produced: 5 Produced: 6 Produ 7 Prot Produc Consum Consumed: 1 Consumed: 2 Consumed: 3 Consumed: 4 Consumed: 5 Consul 6 Consumed Consumed: 8 38) What is the difference between Java Callable interface and Runnable interface? The Callable interface and Runnable interface both are used by the classes which wanted to execute with multiple threads. However, there are two main differences between the both : © A Callable
interface can return a result, whereas the Runnable interface cannot return any result. © A Callable
interface can throw a checked exception, whereas the Runnable interface cannot throw checked exception, © A Callable
interface cannot be used before the Java 5 whereas the Runnable interface can be used, 39) What is the Atomic action in Concurrency in Java? © The Atomic action is the operation which can be performed in a single unit of a task without any erference of the other operations. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions zat‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint The Atomic action cannot be stopped in between the task. Once started it fill stop after the completion of the task only. An increment operation such as a++ does not allow an atomic action. All reads and writes operation for the primitive variable (except long and double) are the atomic operation. All reads and writes operation for the volatile variable (including long and double) are the atomic operation. The Atomic methods are available in java.util. Concurrent package. 40) What is lock interface in Concurrency API in Java? The javautil.concurrent_ocks.Lock interface is used as the synchronization mechanism. It works similar to the synchronized block. There are a few differences between the lock and synchronized block that are given below. Lock interface provides the guarantee of sequence in which the waiting thread will be given the access, whereas the synchronized block doesn't guarantee it. Lock interface provides the option of timeout if the lock is not granted whereas the synchronized block doesn't provide that. The methods of Lock interface, i.e, Lock() and Unlock() can be called in different methods whereas single synchro ed block must be fully cont ed in a single method, 41) Explain the ExecutorService Interface. The ExecutorService Interface is the subinterface of Executor interface and adds the features to manage the lifecycle. Consider the following example. tps: javatpoint comjava-mulithreadinginlrviow-questions 20a‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint import java, oncurrent.ExecutorService; import java.util.concurrent.Executors; import java.utilconcurrent TimeUnit; public class TestThread { public static void main(final String[] arguments) throws InterruptedException ( ExecutorService e = Executors.newSingleThreadExecutor(); try ( esubmit(new Thread); System.out printin(“Shutdown executor"); eshutdown); e.awaitTermination(5, TimeUnit SECONDS); } catch (InterruptedException ex) { System.err printin( "tasks interrupted’); } finally ( if (eisTerminated() ( System.err.printin("‘cancel non-finished tasks"); } eshutdownNow(); System.out printin(“shutdown finished"); static class Task implements Runnable ( public void rund { try{ Long duration = (long) (Math.randomd * 20); |nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 2501‘222m, 1159 PM Java Multhreading Interview Questions (2023) -jvatpoint System.out printin(’Running Task! TimeUnit SECONDS sleep (duration); } catch (InterruptedException ex) { ex printStackTrace); Output Shutdown executor shutdown finished 42) What is the difference between Synchronous programming and Asynchronous programming regarding a thread? Synchronous programming: In Synchronous programming model, a thread is assigned to complete a task and hence thread started working on it, and it is only available for other tasks once it will end the assigned task. Asynchronous Programming: In Asynchronous programming, one job can be completed by multiple threads and hence it provides maximum usability of the various threads 43) What do you understand by Callable and Future in Java? Java Callable interface: In JavaS callable interface was provided by the package java.util.concurrent, It is similar to the Runnable interface but it can return a result, and it can throw an Exception. It also provides a run() method for execution of a thread. Java Callable can return any object as it uses Generic. Syntax: public interface Callable
Java Future interface: Java Future interface gives the result of a concurrent process. The Callable interface returns the object of java.util.concurrent.Future. nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 26001‘2122022, 11:53 PM Java Multthreasing Interview Questions (2023) javatpoint Java Future provides following methods for implementation, © cancel(boolean maylnterruptifRunning): It is used to cancel the execu! task. n of the assigned © get(): It waits for the time if execution not completed and then retrieved the result. © isCancelled(): It returns the Boolean value as it returns true if the task was canceled before the completion, © isDone(: It returns true if the job is completed successfully else returns false. 44. What is the difference between ScheduledExecutorService and ExecutorService interface? ExecutorServcie and ScheduledExecutorService both are the interfaces of java.util. Concurrent package but scheduledExecutorService provides some additional methods to execute the Runnable and Callable tasks with the delay or every fixed time period 45) Define FutureTask class in Java? Java FutureTask class provides a base implementation of the Future interface. The result can only be obtained if the execution of one task is completed, and if the computation is not achieved then get method will be blocked, If the execution is completed, then it cannot be re-started and can't be canceled. Syntax public class FutureTask
extends Object implements RunnableFuture
Java Basics Interview Questions Java OOPs Interview Questions Java Multithreading Interview Questions Java String & Exception Interview Questions Java Collection Interview Questions JDBC Interview Questions tps: javatpointconvjava-multthreadinginlrviow-questions 2112122022, 11:53 PM Java Multthreacing interview Questions (2028) javatpoint Servlet Interview Questions JSP Interview Questions Spring Interview Questions Hibernate Interview Questions PL/SQL Interview Questions SQL Interview Questions Oracle Interview Questions Android Interview Questions SQL Server Interview Questions MySQL Interview Questions You may also like: © Java Interview Questions © SQL Interview Questions © Python Interview Questions © JavaScript Interview Questions © Angular Interview Questions © Selenium Interview Questions © Spring Boot Interview Questions © HR Interview Questions © C Programming Interview Questions © C+ Interview Questions © Data Structure Interview Questions nps:iiwwjavatpoin comijava-multhreading-nlerview-questions12122122, 1:53 PM Java Multthreasing Interview Questions (2023) javatpoint © DBMS Interview Questions © HTML Interview Questions © IAS Interview Questions © Manual Testing Interview Questions © OOPS Interview Questions © Net Interview Questions © Cif Interview Questions © ReactIS Interview Questions © Networking Interview Questions © PHP Interview Questions © CSS Interview Questions © Nodejs Interview Questions © Spring Interview Questions © Hibemate Interview Questions © AWS Interview Questions © Accounting Interview Questions Learn Latest Tutorials Splunk tutorial 2SPSS tutorial Splunk spss Tumblr tutorial React tutorial Tumble WR Programming (ERIS tutorial tutorial RxIS R Programming nps:iiwwjavatpoin comijava-multhreading-nlerview-questions 2 Swagger ‘tutorial Swagger # Regex tutorial Rey ) React Native tutorial React Native AT-SQL tutorial ‘Transact-SQL w. Reinforcement earning tutorial Reinforcement Learning we. Python Design Patterns Python Design Patterns 29801‘2122022, 11:53 PM i) Python Pillow tutorial Preparation 'ython Pillow Aptitude Aptitude B_ Company Interview Questions Company Questions Java Multthreasing Interview Questions (2023) javatpoint ) Python Turtle tutorial Python Turtle ‘Logical Reasoning Reasoning. Trending Technologies 2) Artificial Intelligenc Tutorial Antificial Intelligence FHadoop tutorial Hadoop #) Blockchain Tutorial Blockchain B.Tech / MCA iZAWS Tutorial AWS A ReactIS Tutorial ReactIS Git Tutorial Git nps:iiwwjavatpoin comijava-multhreading-nlerview-questions wKeras tutorial Keras Verbal Ability ‘Verbal Ability 2) Selenium tutorial Selenium #) Data Science Tutorial Data Science Machine Learning Tutorial Machine Learning, Interview Questions Interview Questions 2 Cloud Computing tutorial Cloud Computing 2 Angular7 Tutorial Angular 7 we. DevOps. Tutorial DevOps 0:3112122122, 1:53 PM (DBMS tutorial DBMS 2 Computer Network tutorial Computer Network (PEthical Hacking Tutorial Ethical Hacking, Cyber Security tutorial Cyber Security Hava tutorial Java 2 Control ‘Systems tutorial Control System Java Multthreasing Interview Questions (2023) javatpoint Data Structures tutorial Data Structures 2) Compiler Design tutorial Compiler Design 2 Computer Graphies Tutorial Computer Graphies A Automata ‘Tutorial Automata 2 Net Framework tutorial Net D) Data Mining Tutorial Data Mining nps:iiwwjavatpoin comijava-multhreading-nlerview-questions DAA tutorial DAA B Computer Organization and Architecture Computer Organizs 2 Software Engineering Tutorial Software Engineering, i) C Language tutorial C Programming #Python tutorial Python 2 Data Warehouse Tutorial Data Warehouse Operating System tutorial Operating System 2 Discrete Mathematics Tutorial Discrete ‘Mathematics (Zbtml tutorial Web Technology WiC t+ tutorial cH 2 Listof Programs Programs aya
You might also like
Hourglass Workout Program by Luisagiuliet 2
PDF
76% (21)
Hourglass Workout Program by Luisagiuliet 2
51 pages
12 Week Program: Summer Body Starts Now
PDF
87% (46)
12 Week Program: Summer Body Starts Now
70 pages
Read People Like A Book by Patrick King-Edited
PDF
57% (82)
Read People Like A Book by Patrick King-Edited
12 pages
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
PDF
77% (13)
Livingood, Blake - Livingood Daily Your 21-Day Guide To Experience Real Health
260 pages
Cheat Code To The Universe
PDF
94% (79)
Cheat Code To The Universe
34 pages
Facial Gains Guide (001 081)
PDF
91% (45)
Facial Gains Guide (001 081)
81 pages
Curse of Strahd
PDF
95% (467)
Curse of Strahd
258 pages
The Psychiatric Interview - Daniel Carlat
PDF
91% (34)
The Psychiatric Interview - Daniel Carlat
473 pages
The Borax Conspiracy
PDF
91% (57)
The Borax Conspiracy
14 pages
The Secret Language of Attraction
PDF
86% (108)
The Secret Language of Attraction
278 pages
How To Develop and Write A Grant Proposal
PDF
83% (542)
How To Develop and Write A Grant Proposal
17 pages
Penis Enlargement Secret
PDF
60% (124)
Penis Enlargement Secret
12 pages
Workbook For The Body Keeps The Score
PDF
89% (53)
Workbook For The Body Keeps The Score
111 pages
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
PDF
83% (1016)
Donald Trump & Jeffrey Epstein Rape Lawsuit and Affidavits
13 pages
KamaSutra Positions
PDF
78% (69)
KamaSutra Positions
55 pages
7 Hermetic Principles
PDF
93% (30)
7 Hermetic Principles
3 pages
27 Feedback Mechanisms Pogil Key
PDF
77% (13)
27 Feedback Mechanisms Pogil Key
6 pages
Frank Hammond - List of Demons
PDF
92% (92)
Frank Hammond - List of Demons
3 pages
Phone Codes
PDF
79% (28)
Phone Codes
5 pages
36 Questions That Lead To Love
PDF
91% (35)
36 Questions That Lead To Love
3 pages
How 2 Setup Trust
PDF
97% (307)
How 2 Setup Trust
3 pages
The 36 Questions That Lead To Love - The New York Times
PDF
91% (35)
The 36 Questions That Lead To Love - The New York Times
3 pages
100 Questions To Ask Your Partner
PDF
78% (36)
100 Questions To Ask Your Partner
2 pages
Satanic Calendar
PDF
25% (56)
Satanic Calendar
4 pages
The 36 Questions That Lead To Love - The New York Times
PDF
95% (21)
The 36 Questions That Lead To Love - The New York Times
3 pages
Jeffrey Epstein39s Little Black Book Unredacted PDF
PDF
75% (12)
Jeffrey Epstein39s Little Black Book Unredacted PDF
95 pages
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
PDF
100% (8)
14 Easiest & Hardest Muscles To Build (Ranked With Solutions)
27 pages
1001 Songs
PDF
70% (73)
1001 Songs
1,798 pages
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
PDF
23% (954)
The 4 Hour Workweek, Expanded and Updated by Timothy Ferriss - Excerpt
38 pages
Zodiac Sign & Their Most Common Addictions
PDF
63% (30)
Zodiac Sign & Their Most Common Addictions
9 pages
34 Java Collections Interview Questions
PDF
No ratings yet
34 Java Collections Interview Questions
21 pages
3.java Multithreading Interview Questions (2023) - Javatpoint
PDF
No ratings yet
3.java Multithreading Interview Questions (2023) - Javatpoint
29 pages
Multithreading Interview Questions
PDF
No ratings yet
Multithreading Interview Questions
20 pages
Java Multithreading
PDF
No ratings yet
Java Multithreading
1 page
Multi Threading
PDF
No ratings yet
Multi Threading
17 pages
MultithreadingInterview Questions
PDF
No ratings yet
MultithreadingInterview Questions
31 pages
Interview Questions Faqs On Multithreading
PDF
No ratings yet
Interview Questions Faqs On Multithreading
6 pages
23 Question Related To Multithreading
PDF
No ratings yet
23 Question Related To Multithreading
11 pages
Top 20 Interview Questions On Java Multithreading
PDF
No ratings yet
Top 20 Interview Questions On Java Multithreading
4 pages
Multithreading Interview Questions: Click Here
PDF
No ratings yet
Multithreading Interview Questions: Click Here
37 pages
Threads and Concurrency
PDF
No ratings yet
Threads and Concurrency
2 pages
multi threading
PDF
No ratings yet
multi threading
5 pages
Java Module5 All Answers
PDF
No ratings yet
Java Module5 All Answers
6 pages
Multithreading
PDF
No ratings yet
Multithreading
1 page
multithread
PDF
No ratings yet
multithread
11 pages
Multithreading in Java
PDF
No ratings yet
Multithreading in Java
26 pages
New Uploading Disha 1
PDF
No ratings yet
New Uploading Disha 1
2 pages
Java Threads
PDF
No ratings yet
Java Threads
12 pages
Java Threads Interview Questions Answers
PDF
No ratings yet
Java Threads Interview Questions Answers
5 pages
Questions Java
PDF
No ratings yet
Questions Java
32 pages
QB104344
PDF
No ratings yet
QB104344
7 pages
Advanced JAVA-10 marks
PDF
No ratings yet
Advanced JAVA-10 marks
40 pages
MultiTheading IQs
PDF
No ratings yet
MultiTheading IQs
3 pages
Session 6 - Multithreading - Collection Framework
PDF
No ratings yet
Session 6 - Multithreading - Collection Framework
14 pages
Asg Soln
PDF
No ratings yet
Asg Soln
4 pages
Unit 4_LMS
PDF
No ratings yet
Unit 4_LMS
43 pages
ENotes 1329 Content Document 20250128121915PM
PDF
No ratings yet
ENotes 1329 Content Document 20250128121915PM
48 pages
Unit IV Final
PDF
No ratings yet
Unit IV Final
108 pages
CH 6
PDF
No ratings yet
CH 6
91 pages
Multi Threading
PDF
No ratings yet
Multi Threading
9 pages
r38
PDF
No ratings yet
r38
3 pages
Java 4
PDF
No ratings yet
Java 4
65 pages
Unit 5
PDF
No ratings yet
Unit 5
44 pages
CS8392 - OOPs - UNIT - 4 - PPT - 4.1
PDF
No ratings yet
CS8392 - OOPs - UNIT - 4 - PPT - 4.1
76 pages
Java Multithreading Interview Questions: Concurrency
PDF
No ratings yet
Java Multithreading Interview Questions: Concurrency
14 pages
Threading
PDF
No ratings yet
Threading
36 pages
CS8392 - OOPs - UNIT - 4 - PPT - 4.1
PDF
No ratings yet
CS8392 - OOPs - UNIT - 4 - PPT - 4.1
76 pages
Multi Threading Interview Questions PDF
PDF
No ratings yet
Multi Threading Interview Questions PDF
4 pages
java_unit2 (1)
PDF
No ratings yet
java_unit2 (1)
30 pages
Multithreading in Java
PDF
No ratings yet
Multithreading in Java
18 pages
Day 5 Viva
PDF
No ratings yet
Day 5 Viva
23 pages
Chapter 2 - Multithreading - PPTX (Autosaved)
PDF
No ratings yet
Chapter 2 - Multithreading - PPTX (Autosaved)
46 pages
Unit 4 Java
PDF
No ratings yet
Unit 4 Java
22 pages
Multithreading in Java: Multitasking
PDF
No ratings yet
Multithreading in Java: Multitasking
28 pages
Top 50 Java Thread Interview Questions Answers For Experienced
PDF
No ratings yet
Top 50 Java Thread Interview Questions Answers For Experienced
60 pages
Multithreading in Java With Examples: Multitasking Vs Multithreading Vs Multiprocessing Vs Parallel Processing
PDF
No ratings yet
Multithreading in Java With Examples: Multitasking Vs Multithreading Vs Multiprocessing Vs Parallel Processing
3 pages
Multithreading in Java
PDF
No ratings yet
Multithreading in Java
45 pages
E-Notes_790_Content_Document_20240917091004PM
PDF
No ratings yet
E-Notes_790_Content_Document_20240917091004PM
40 pages
Unit 4
PDF
No ratings yet
Unit 4
40 pages
UNIT 4 NOTES Oops
PDF
No ratings yet
UNIT 4 NOTES Oops
15 pages
Multithreading
PDF
No ratings yet
Multithreading
35 pages
Threads in Java
PDF
No ratings yet
Threads in Java
23 pages
Chapter 6-7
PDF
No ratings yet
Chapter 6-7
15 pages
Multi Threading
PDF
No ratings yet
Multi Threading
14 pages
Java Unit - 5 Notes
PDF
No ratings yet
Java Unit - 5 Notes
33 pages
Javatpoint Multithreading
PDF
No ratings yet
Javatpoint Multithreading
16 pages
UNIT-5 new
PDF
No ratings yet
UNIT-5 new
46 pages
OOPS U4
PDF
No ratings yet
OOPS U4
44 pages
Java Unit-3 Student
PDF
No ratings yet
Java Unit-3 Student
92 pages
Networking-10 Marks(All Units)
PDF
No ratings yet
Networking-10 Marks(All Units)
40 pages
Formal Methods For Software Engineering Languages, Methods, Application
PDF
No ratings yet
Formal Methods For Software Engineering Languages, Methods, Application
537 pages
JDBC Interview Questions
PDF
No ratings yet
JDBC Interview Questions
22 pages
Connection
PDF
No ratings yet
Connection
6 pages
Java Runtime Class
PDF
No ratings yet
Java Runtime Class
9 pages
Daemon Thread in Java
PDF
No ratings yet
Daemon Thread in Java
8 pages