Skip to main content

The Mutex and Lock Management

  • Chapter
Taming Java Threads
  • 247 Accesses

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.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

eBook
USD 24.99
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 16.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

Authors

Rights and permissions

Reprints 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

Publish with us

Policies and ethics