×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31

    overview of System threads

    i have a question that concerns threads.

    are the Thread that runs my code, also used by the application manager for other things. so i makes my code hang some time.

    how many threads does the system runs and what are they used for.

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I'm not sure if there's a definite answer to your question - what threads get used for what is probably "implementation-specific". Are you having a problem with your app hanging? In what situation?

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    yes my game hangs, and i cant see why.

    i have made a small version of my own game just to see why it hangs.

    in that version i have full control over all objects and variables. they are all global and reused all the time, there is nothing for the GC there.

    i have the main exec thread for the function part of my game loop , and a seperat thread for my draw loop.

    the deaw loop only runs if there is any updates to the screen. it uses a wait(), and get called from the function loop with a notify();

    but when i scroll my game, it hangs once in a while. and i can't find out why.

    so i would like an overview of the threads run by the app manager to see if it could be one of them that blocks once in a while.

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    I have experienced something similar, with my application apparently deadlocking without an obvious cause. System threads should not acquire any object-locks, unless an event-handler method you write - like paint() - acquires any. I fixed my problem by changing the design to use one thread instead of two. I appreciate that this may not be possible in your case!

    The MIDP specification says that you "should not hold any locks when serviceRepaints() is called". serviceRepaints() might call paint() with the same thread, or a different thread, so you should certainly not hold locks that paint() needs. But the spec seems to say that the entire program should not hold any locks on anything!

    As you have a cut-down version of your game, it might be worth trying some different design approaches with it. For example, what if you create a new drawing thread when needed, and let it die, rather than keeping the same one asleep? That would avoid the synchronization issue, at the cost of a small amount of garbage.

    I'm afraid that's about as much help as I can be!!

    Graham.

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    i can't that i have any locks, but maybe im not looking for the right thing.
    can you give me an example..

    i have some synch. blocks for the wait statement, but thats all.

    i have a thread for the draw loop, and it dosent do anything else. i use the wait() on it, every time around, and them wake it up with a notify() from my function loop when there is an update to the screen.

    every time my paint loop runs , the mem free size goes down, i put a Runtime.getRuntime().gc(); in my loop and i stops the mem from going down , but at the expence of speed...
    i cant se that i use any new mem in my loop...

    i only have the main exec thread + one for my draw loop.

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    Your memory will go down every paint(), as the system creates a new Graphics object for you.

    By locks I mean synchronized {} blocks, or methods declared synchronized. There should be no locks held during a wait()... you acquire the lock, then release it again while you wait() (automatically).

    I experienced a lockup in the same situation, and cured it only by changing the design so as not to use synchronization. Made no sense to me, but that's not a new experience!!

  7. #7
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    i have now removed all synchronized blocks and wait's. and
    put in a call to callserialy(). it has totaly boosted my game, but i have still some ticks when i try to scroll from start to finish.

    i found a wery good optimize checklist on the net , and checked against my code.

    i cant figure out whats making the ticks.


    did you totaly get rid of hangs and ticks when you did that.

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395
    When I got rid of the need for synchronization, the deadlocks disappeared completely. I don't use any animation, so I don't get any "ticks", though I do sometimes get slight delays if I choose a command quickly after a screen appears. I'm blaming these on garbage collection; I've added a System.gc() to the end of another time-consuming task so that this gets done when the user isn't expecting to be able to do anything anyway, and so far the software seems more responsive.

    I have no experience with games, but plenty here do, so it's probably worth your while to post a new question in the graphics forum about your animation problem. (If you haven't already!!)

    Where did you find your checklist?

    Cheers,
    Graham.

  9. #9
    Registered User
    Join Date
    Mar 2003
    Location
    Denmark
    Posts
    31
    hi

    i found this great aticle on optimizing j2me games
    http://www.developer.com/java/j2me/p...0934_2234631_1

    i use Runtime.getRuntime().gc(); , because System.gc(); has no effect om my phone and emulator.

    but i still cant get rid of the little ticks, they show on both the emulator and the phone. i use Nokia UI API so i cant use the profiler thats comes with sun's WTK. are there any other means of profiling.

    my game is wery responsive, all that runs perfect and i get allmost 20fps. i have used 2 months streamlining my code, and that has paid off. the only thing i need is to get rid of the ticks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×