This noncompliant code example can deadlock because of excessive synchronization. Noncompliant Code Example (Different Lock Orders) These issues can be resolved by letting each waiting thread retry the operation at random intervals until they successfully acquire the resource. For example, liveness issues can arise when two or more threads are waiting for each other to release resources such as database connections. This rule also applies to programs that need to work with a limited set of resources. Do not use Thread.stop() to terminate threads for more information). Furthermore, the Thread.stop() and stroy() methods are deprecated (see THI05-J. For example, the paint(), dispose(), stop(), and destroy() methods should never be synchronized in an applet because they are always called and used from dedicated threads. Consequently, programs are required to avoid deadlock by acquiring and releasing locks in the same order.Īdditionally, synchronization should be limited to cases where it is absolutely necessary. Deadlock can occur when two or more threads request and release locks in different orders. Java neither prevents deadlocks nor requires their detection. However, excessive use of locking can result in deadlocks. Locking can be performed at the object level using synchronized methods, synchronized blocks, or the dynamic lock objects. To avoid data corruption in multithreaded Java programs, shared data must be protected from concurrent modifications and accesses.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |