Java applet "pauses" for 5 seconds or more...

Discussion in 'Game Development (Technical)' started by John Cutter, Dec 27, 2006.

  1. John Cutter

    John Cutter New Member

    Joined:
    Dec 12, 2006
    Messages:
    37
    Likes Received:
    0
    Java applet freezes for 5 seconds or more...

    We recently finished a java applet card game (Fairway Solitaire) that tends to freeze at completely random times once or twice every hour. These freezes will last for five to ten seconds and they basically cause everything on screen to stop moving or animating.

    To make matters worse, players will often click on the draw pile, and then, when nothing happens, click it again. So when the game comes back both mouse clicks are processed and players end up drawing two cards, thus wasting one.

    The programmer said there is nothing in the code that should cause the game to pause like that and we're wondering if it's automatic garbage collection. But would GC cause delays of five to ten seconds?? Is there anything we can do to improve this situation?
     
    #1 John Cutter, Dec 27, 2006
    Last edited: Dec 27, 2006
  2. Jesse Aldridge

    Original Member

    Joined:
    Apr 19, 2005
    Messages:
    221
    Likes Received:
    0
    That's pretty weird. I've never heard of it happening before. I'm 99% sure it's something in your code that's causing the problem though, and not a Java bug or some such.

    It does sound like your problem could be related to garbage collection. If it was, I would guess that you keep allocating more and more memory without any of your variables going out of scope and getting garbage collected. Then, when memory gets low, Java "forces" a deletion of certain variables. You could check if something like this is happening by just doing a ctrl+alt+delete and checking the amount of memory Java is using (assuming windows). (That's just a guess - I'm not really sure how Java works under the hood).

    Another random thing that could be going wrong is if your using fancy thread stuff... for example sychronized doesn't work with applets (or is it Java 1.4 it doesn't work with? anyway, it doesn't work for me). Just a thought.
     
  3. Oaf

    Oaf
    Original Member

    Joined:
    Jul 30, 2004
    Messages:
    136
    Likes Received:
    0
    Try forcing a garbage collect every so often, or at points where a potential drop in performance won't be noticed.

    I notice a pause in my game every time mail arrives....
     
  4. John Cutter

    John Cutter New Member

    Joined:
    Dec 12, 2006
    Messages:
    37
    Likes Received:
    0
    Thanks for the replies! Can garbage collection take five to ten seconds?? When I heard about this automatic feature in Java I assumed that the time would be measured in milliseconds. (Not thousands of milliseconds.)

    Any other thoughts? The pauses seem to come at completely random times and we've seen this behavior in other games, as well.
     
  5. jetro

    Original Member

    Joined:
    Jan 21, 2005
    Messages:
    130
    Likes Received:
    0
    Sounds quite weird to me. Do you have any specifics of hardware setups where this happen, including used browser & Java version?
     
  6. John Cutter

    John Cutter New Member

    Joined:
    Dec 12, 2006
    Messages:
    37
    Likes Received:
    0
    It has been reported by a large number of our users, so I suspect a diverse range of hardware configurations and java versions (we require 1.5 or better).
     
  7. MrQ

    MrQ New Member

    Joined:
    Oct 4, 2006
    Messages:
    198
    Likes Received:
    0
    Some programmers like to point the finger everywhere but at thier own code. Normally a process of elimination will prove them wrong ;) It's probably a good idea to start collecting system specs from the users having problems and trying to repro the issue so you can debug it. And get that programmer to fix, SlackeR! :D
     
  8. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    Run the applet separately in appletviewer, and get some GC profiling output (run with -verbose:gc on the command line). It's unlikely it's GC that's causing the issue but there is a case in the AWT to do with images (I forget specifically what, just remember this issue some time ago) which causes a load of large objects with finalizers to start filling up the heap.

    The problem with the finalize() method is that if it exists the objects aren't collected routinely but only very occasionally, and when they're collected they're much slower than a normal GC. So what happens is the heap fills up fast (esp. if such objects are created in your rendering loop), and extends itself to its maximum size, and then the GC takes abnormally long to deal with it.

    Cas :)
     
  9. gosub

    Original Member

    Joined:
    Sep 10, 2005
    Messages:
    151
    Likes Received:
    0
    Tell your programmer to place timing code around all the major sections of code which can detect these delays. Assuming it's not GC, he should be able to narrow it down to a section of code, and then to a single function call.

    BTW, On some hardware configurations I've seen the DirectX Present() function delay for *exactly* 10 seconds. I don't know what the Java equivalent is, but definitely concentrate on all draw and render function calls.

    -Jeremy
     
  10. oNyx

    Original Member

    Joined:
    Jul 26, 2004
    Messages:
    1,211
    Likes Received:
    0
    Na... no need to put timing code anywhere. Just profile it. You can also inject timing code (via profiling) if you want really accurate figures, but that slowdowns the app quite a lot. The usual "samples" method works good enough and you only get a slight slowdown.

    java -agentlib:hprof=help

    Will display the help text.

    Also try -verbose:gc as Cas suggested.
     
  11. spellcaster

    Original Member

    Joined:
    Mar 27, 2006
    Messages:
    259
    Likes Received:
    0
    I don't think it's related to GC.
    I have the same problem after switching my computer with "Titan Attacks" - i just hangs for a couple of seconds, normally during start up.
    I've no idea what's causing it, upgrading to a newer java version didn't solve the problem - so I think it's somehow driver related.
    The same version of TA works nicely on my older box - it's quite strange.
     
  12. princec

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    4,873
    Likes Received:
    0
    If it's the windows version then, yes, definitely driver related, as Titan for Windows has it's own JVM. To test it out on your native VM you need to hit the Linux (Webstarted) version.

    Cas :)
     
  13. spellcaster

    Original Member

    Joined:
    Mar 27, 2006
    Messages:
    259
    Likes Received:
    0
    Same behavior using the WebStart version - the main windows starts and then zthere is around 5seconds delay before the puppy games screen with the progress bar.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer