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 6720423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:12:38+00:00 2026-05-26T09:12:38+00:00

I’m having a strange issue. In a class I have: private final ScheduledExecutorService executor

  • 0

I’m having a strange issue.

In a class I have:

private final ScheduledExecutorService executor 
     = Executors.newSingleThreadScheduledExecutor();

public MyClass(final MyService service) {
    executor.scheduleAtFixedRate(new Runnable() {
        @Override
        public void run() {
            service.foo();
        }
     }, 0, 30, TimeUnit.SECONDS);
}

MyService is a spring bean that has @Transactional on its foo method. MyClass is instantiated only once (effectively singleton in the application)

After the first invocation of service.foo() (which works fine), on subsequent requests to the application I am randomly getting:

java.lang.IllegalStateException: Already value [SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])] for key [org.hibernate.impl.SessionFactoryImpl@2cd91000] bound to thread [http-bio-8080-exec-10]

A few observations:

  • when the exception is thrown, the session stored in the TransactionSynchronizationManager is closed
  • the transaction synchronization manager resource map for the manually scheduled thread is empty
  • the exception occurs in http-bio-8080-exec threads, but the manually scheduled one is a pool- thread – so there is no ‘thread polution’
  • MyClass is instantiated on startup, in a thread named “Thread-5”, i.e. it is not in any way related to the http-bio threads.

If I comment the invocation to service.foo(), or get rid of the @Transactioanl annotation, everything works (except, of course, that data is not inserted in the db)

Any clues what the issue might be?

(Note: I prefer not to use @Scheduled – I don’t want MyClass to be a spring bean, and the runnable has to operate on some of its internal state before invoking the service)

Update: After a while I’m able to reproduce it even without the scheduling stuff. So probably a general spring problem with the latest snapshot I’m using.

  • 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-26T09:12:38+00:00Added an answer on May 26, 2026 at 9:12 am

    I assume that exception comes from an invocation of the TransactionInterceptor or the like (some Spring infrastructure bean), or are you using the TransactionSynchronizationManager from your own code somewhere? It appears to me that something is binding sessions to a thread being managed by your container (is that Tomcat 7?) and failing to unbind them before they’re returned to the container’s thread pool. Thus when the same thread is used for another transactional request later, Spring can’t bind the new Session to it because the old one wasn’t cleaned up.

    I don’t actually see anything to make me think it’s directly related to your custom scheduling with MyClass. Are you sure it’s not just a coincidence that you didn’t see the exception when you remove the service.foo() call?

    If you could catch one of those threads in a debugger when it’s being returned to the pool with a Session still bound to it, you might be able to backtrack to what it was used for. An omniscient debugger would theoretically be perfect for this, though I’ve never used one myself: ODB and TOD are the two I know of.

    Edit: An easier way to find the offending threads: add a Filter (servlet filter, that is) to your app that runs “around” everything else. After chain.doFilter(), as the last act of handling a request before it leaves your application, check the value of TransactionSynchronizationManager.getResourceMap(). It should be an empty map when you’re done handling a request. When you find one that isn’t, that’s where you need to backtrack from to see what happened.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.