Java 5 added Executor Framework to provide out-of-box thread pool to Java programmers and Java 7 added ForkJoinPool an implementation of ExecutorService which specifically designed to execute ForkJoinTask. The Executor Framework provides several classes e.g. Executor, ExecutorService, and Executors for execution and creating thread pools. It also provides several built-in, ready to use thread pools like a pool of fixed threads, cached thread pool which can expand itself, spawn new threads if required due to heavy load.
Read more »
Showing posts with label thread interview questions. Show all posts
Showing posts with label thread interview questions. Show all posts
Thursday, 1 December 2016
Saturday, 20 August 2016
5 Essential difference between Callable and Runnable interface in Java?
The difference between Callable and Runnable is one of the most frequently asked multi-threading and concurrency interview question in Java world. I remember, it was 2007 when I first heard about Callable interface and that too on a telephonic interview. Till then, I was happy using Runnable to implement threads and just started paying attention to Java 1.5, as most of the application by then using Java 1.4. That one interview question encouraged me to learn more about several other useful features introduced in Java 5 concurrency library e.g. CountDownLatch, CyclicBarrier, Semaphore, Atomic variables, and Thread pool. This is one of the reasons I always encourage Java developer to give/take regular interviews, just to update your knowledge.
Read more »
Friday, 22 April 2016
Difference between notify and notifyAll in Java - When and How to use
notify vs notifyAll in Java
Read more »
What is the difference between notify and notifyAll method is one of the tricky Java questions, which is easy to answer but once Interviewer asks follow-up questions, you either got confused or not able to provide clear-cut and to the point answers? The main difference between notify and notifyAll is that notify method will only notify one Thread and notifyAll method will notify all Threads which are waiting on that monitor or lock. By the way, this is something you have been reading in all over places and to be frank, this statement despite being correct is not complete and its very difficult to understand difference between notify vs notifyAll by just reading this statement. Lot of questions comes in mind like
Which thread will be notified if I use notify()?
How do I know how many threads are waiting, so that I can use notifyAll() ?
How to call notify()?
What are these thread waiting for being notified etc?
Actually, discussion of notify and notifyAll is incomplete without discussing wait method in Java and I had touched based on this on my earlier article why to wait and notify must be called from synchronized context. In for order to get answer to those questions and understand difference between notify and notifyAll we will use a simple Java Thread example using wait and notify code :
Tuesday, 19 April 2016
Difference between ExecutorService.submit() and Executor.execute() methods in Java?
What is the difference between Executor.submit() and Executor.execute() method in Java? is one of the good multi-threading questions for experienced Java programmers, mostly asked in Investment Banks like Barclays, Deutsche Bank, or Citibank. A main difference between the submit() and execute() method is that ExecuterService.submit()can return result of computation because it has a return type of Future, but execute() method cannot return anything because it's return type is void. The core interface in Java 1.5's Executor framework is the Executor interface which defines the execute(Runnable task) method, whose primary purpose is to separate the task from its execution.
Read more »
Thursday, 24 March 2016
Difference between Wait and Sleep, Yield in Java
The difference between wait and sleep or the difference between sleep and yield in Java are one of the popular core Java interview questions and asked on multi-threading interviews. Out of three methods which can be used to pause a thread in Java, sleep() and yield() methods are defined in thread class while wait() is defined in the Object class, which is another interview question. The key difference between wait() and sleep() is that former is used for inter-thread communication while later is used to introduced to pause the current thread for a short duration. This difference is more obvious from the fact that, when a thread calls the wait() method, it releases the monitor or lock it was holding on that object, but when a thread calls the sleep() method, it never releases the monitor even if it is holding.
Wednesday, 9 March 2016
Top 50 Java Thread Interview Questions Answers for Experienced
You go to any Java interview, senior or junior, experience or freshers, you are bound to see a couple of questions from the thread, concurrency, and multi-threading. In fact, this built-in concurrency support is one of the strongest points of Java programming language and helped it to gain popularity among enterprise world and programmers equally. Most of lucrative Java developer position demands excellent core Java multi-threading skills and experience in developing, debugging and tuning high-performance low latency concurrent Java applications. This is the reason, it is one of the most sought after skill on Java interviews. The multithreading and concurrency are also hard to master concept and only good developers with solid experience can effectively deal with concurrency issues.
Read more »
Subscribe to:
Posts (Atom)