Synchronization is a process of restricting concurrent access to the shared resources. As synchronization is a performance issue, we should be very much careful fo decide at which part of the code the problem may occur. At that place provide a synchronized block or simply provide a synchronized method. just use the key word synchronized before the method or block. Please note that we can synchronize only blocks or methods. we can not synchronize variables or classes. By creating locks automatically by using wait(), notify() and notifyAll() methods the Java Virtual machine taking care of inner implementation.
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.
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.
Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client?s requests through service() method. c) The server removes the servlet through destroy() method.
There are two ways of achieving multi-threading : By implementing Runnable interface. By extending Thread class.
With respect to multithreading, synchronization is the capability to control the access of multiple threads to shared resources. Without synchronization, it is possible for one thread to modify a shared object while another thread is in the process of using or updating that object?s value. This often leads to significant errors.
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.
wait(), notify() and notifyAll() are all part of Object class and they have to be called from synchronized code only
Bean life cycle in Spring Bean Factory Container is as follows:
Ads By Google
© 2018 - JavaSpartans.com • All Rights Reserved