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

  • Home
  • SEARCH
  • 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 6656007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:35:26+00:00 2026-05-26T01:35:26+00:00

We hit an extremely surprising exception today. Inside of a synchronized block, we call

  • 0

We hit an extremely surprising exception today. Inside of a synchronized block, we call wait() and it throws IllegalMonitorStateException. What can cause this?

This is happening in well-tested open source code:
http://svn.apache.org/viewvc/river/jtsk/trunk/src/com/sun/jini/jeri/internal/mux/Mux.java?view=markup#l222

We eliminated the obvious causes:

  • are we synchronized on the right variable? Yes, it’s muxLock
  • is it a mutable variable? No, muxLock is final
  • are we using any weird “-XX:” JVM flags that might affect monitor behavior? No, but we are launching the JVM embedded inside a C++ app via JNI.
  • is this a strange JVM? No, it’s Sun’s 1.6.0_25 win/x64 JRE
  • is this a known JVM bug? Can’t find anything relevant at http://bugs.sun.com/bugdatabase

So, I’m trying to think of more far-fetched explanations.

  • could an uncaught out-of-memory error cause the monitor state to be screwed up? We’re looking at this, but we’re seeing no evidence of memory errors yet.

UPDATE: (based on comment)

I’ve also verified from the stacktrace and breakpoint that the thread is indeed inside the synchronized block when the exception is thrown. It’s not the case that some other unrelated code is emitting the exception (unless something is REALLY confusing Eclipse!)

  • 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-26T01:35:27+00:00Added an answer on May 26, 2026 at 1:35 am

    The only suspicious thing I see that you are passing a reference to ‘this’ to some other object in your constructor. Is it possible (in fact, not unlikely) that, through weird re-ordering of things, if some other thread gets that reference to ‘this’ and calls the method that uses the muxlock, things can go extremely wrong.

    The Java Language Specification is pretty specific about this:

    An object is considered to be completely initialized when its constructor finishes. A thread that can only see a reference to an object after that object has been completely initialized is guaranteed to see the correctly initialized values for that object’s final fields.

    In other words, if another thread gets hold of the ‘this’ reference before the constructor is finished, the final field ‘muxlock’ might not be correctly initialized yet. In general, publishing a reference to ‘this’ before the constructor has finished can be pretty dangerous, especially in threaded situations.

    Some potentially useful discussion about such things:
    http://madpropellerhead.com/random/20100328-java-final-fields-are-not-as-final-as-you-may-think

    For some older, but still useful general discussion of why publishing ‘this’ in a constructor is a very bad idea in general, see for instance:
    http://www.ibm.com/developerworks/java/library/j-jtp0618/index.html

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

Sidebar

Related Questions

I hit this error while my web application was trying to execute a SELECT
I have hit upon this problem about whether to use bignums in my language
I'm extremely new to cocos2D development and I have hit a problem with my
Forgive me if this is a dupe but I couldn't find anything that hit
Hit the following situtation a couple of times today: Myself and another dev both
I hit this weird namespace issue when adding my first 'Service Reference' to a
This is more a conceptual question. It's inspired from using some extremely large table
Im trying to get this Ruby code beautifier working and have hit on a
I hit Linux's 32,000 subdirectory limit. It caused problems with my PHP scripts and
I hit control + Scroll lock, control + break, and control + every other

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.