Abstract
In the previous two chapters, I focused on the pitfalls of writing multithreaded applications in Java. With this chapter, I’ll show you a few solutions to the problems. I’ll start out with a look at a roll-your-own mutex class that is easier to use than synchronized in some situations. In particular, it allows you to specify a timeout so that you won’t have to wait forever to acquire a lock (as compared to synchronized, which provides no timeout facility). We’ll also look at a lock manager class that lets you safely acquire multiple semaphores without deadlocking. Using objects of these classes rather than the built-in synchronized can save you hours of searching for unexpected deadlocks, and though these classes don’t solve every possible deadlock problem, they’re still pretty useful.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Rights and permissions
Copyright information
© 2000 Allen I. Holub
About this chapter
Cite this chapter
Holub, A. (2000). The Mutex and Lock Management. In: Taming Java Threads. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4302-1129-7_3
Download citation
DOI: https://doi.org/10.1007/978-1-4302-1129-7_3
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-893115-10-1
Online ISBN: 978-1-4302-1129-7
eBook Packages: Springer Book Archive