Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7595183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:36:35+00:00 2026-05-30T21:36:35+00:00

I am thinking here: If you have 2 threads executing FAST operations that need

  • 0

I am thinking here: If you have 2 threads executing FAST operations that need to be synchronized, isn’t a nonblocking approach faster/better than a blocking/context switch approach?

By non-blocking I mean something like:

while(true) {
if (checkAndGetTheLock()) break;
}

The only thing I can think of is starvation (with CPU burn out) if you have too many threads looping around the lock.

How do I balance one approach versus the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:36:36+00:00Added an answer on May 30, 2026 at 9:36 pm

    Here’s what Java Concurrency in Practice says about the subject:

    The JVM can implement blocking either via spin-waiting (repeatedly
    trying to acquire the lock until it succeeds) or bysuspending the
    blocked thread through the operating system. Which is more efficient
    depends on the relationship between context switch overhead and the
    time until the lock becomes available; spin-waiting is preferable for
    short waits and suspension is preferable for long waits. Some JVMs
    choose between the two adaptively based on profiling data of past wait
    times, but most just suspend threads waiting for a lock.

    And also (which is, IMO, the most important point):

    Don’t worry excessively about the cost of uncontended synchronization.
    The basic mechanism is already quite fast, and JVMs can perform
    additional optimizations that further reduce or eliminate the cost.
    Instead, focus optimization efforts on areas where lock contention
    actually occurs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been thinking quite a bit here lately about screen scraping and what
Thinking that the answer to this is pretty obvious but here it goes: When
Context: I have a photo-uploading website set up. I need to perform operations on
Ok, here's the situation... I have an application that generates about 8 files per
I'm thinking how to implement the producer/consumer pattern in Java. Assume that I have
I have intensive processing that I need to perform in a device driver, at
Maybe I'm thinking about this the wrong way but here's the idea: Class A
Reading some questions here on SO about conversion operators and constructors got me thinking
Thinking about a Windows-hosted build process that will periodically drop files to disk to
Thinking about avoiding code replication, I got a question that catches me every time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.