All about Java Multi Threading
Terms used in Multi-threading Daemon threads The daemon threads are basically the low priority threads that provides the background support to the user threads. Thread class setDaemon(true) can be used to create daemon thread in java. We need to call this method before calling start() method else it will throw IllegalThreadStateException. Analyze a deadlock To analyze a deadlock, we need to look at the java thread dump of the application, we need to look out for the threads with state as BLOCKED and then the resources it’s waiting to lock, every resource has a unique ID using which we can find which thread is already holding the lock on the object. Avoid Nested Locks, Lock Only What is Required and Avoid waiting indefinitely are common ways to avoid deadlock situation, read this post to learn how to analyze deadlock in java with sample program. Ways to achieve Synchronization There are several ways to achieve thread safety in java – synchronization, a...