PreviousNext…

Are your threads leaking?

A very useful snippet gleaned from the IBM Support pages: Troubleshooting Java agent message ‘Error cleaning up agent threads’.

The article includes a handy method that can be walloped into your code to assess the state of your threads, and for some lo-fi memory profiling / troubleshooting, this can’t be beat. Well worth book-marking.

Comments

  1. When will IBM fix this joke? One of the key features of Java is automatic garbage collection. Why oh why do java programmers on the Notes platform have to recycle() their objects????? Java programming in Notes is a clunky mess.Brendon Upson#
  2. I'm a total beginner with Java and keep running into weird errors that make no sense and the help doesn't help. I have seen this particular error and eventually gave up and rewrote my code in LotusScript. I never did figure out what the problem was.

    If I run this code and it tells me a certain thread is sitting out there, what am I supposed to do about it? I understand what recycle() does, but how on Earth am I supposed to know where to put it based on a thread ID?

    I'm not venting or whining at you, Ben, I'm just confused by what this is really telling me. :-) I agree with Brendon's assessment: "Java programming in Notes is a clunky mess."Charles Robinson#
  3. No no that’s fair enough Charles! Let me explain. Let’s say you get something like this in the console once your agent’s run:

      ThreadGroup UTG: MyAgent, objid = 1386529359
      subgroups  = 0
      total threads = 3
    
      Thread Name, ThreadID, ThreadGroup
      AgentThread: MyAgent, 82002511, UTG: MyAgent
    

    Three threads, but you finish with just one (that of the agent itself): this is good. If you finish with something like this though:

      Thread Name, ThreadID, ThreadGroup
      AgentThread: MyAgent, 82002511, UTG: MyAgent
      AnotherThread: SomeDbConnect, 82002512, UTG: DbObject
    

    … then you have something going wrong. It’s usually addressed by reviewing your code and ensuring that the relevant objects are disposed-of properly (e.g. in this example, ensuring that database connections are closed, and object drivers set to null).

    Does that help?

    Ben Poole#
  4. Yeah.. a little. It will probably make more sense as I do more with Java. It sounds like I'll end up back in the same mode I was with VB5: if you instantiate it you have to explicitly destroy it. With Java I get to add: and force garbage collection. A right clunky mess indeed. :-) Thanks for the explanation.Charles Robinson#
  5. I tend to defer object recycling and wot-not to a finally block where possible. It’s no panacea, but it helps!Ben Poole#
  6. @1 : is SWT a joke too cause we need to dispose() ? ;-)Michael Bourak#
  7. @6: yesBrendon Upson#
  8. It has to do with the way garbage collection is implemented in the vms. For performance reason the vm does not care about any small objects and the Notes-Java objects are actually small objects from a vm perspective: tiny wrapper, which wrappers huge memory allocated by C-code. And VM does not know about the C-code. At least I understand it that way.
    If you keep some simple, though effective rules in mind, its not so much of a brainer. I have had no problem with larger productively deployed java code in notes production environments.
    I have allways hoped that IBM (or anybody else) would create a garbage collector, which manages this issue more effectively.
    Now, when we will get Notes Designer on Eclipse IBM could add a Builder to the compilation process of Java code in notes designer, which is going to check for promblems with this issue in the code. I don't think this is very complicated, as things like checkstyle or pmd analyze code too. Axel#

Comments on this post are now closed.

About

I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.

";