Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (788)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (862)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  threading troubles  (Read 1574 times)
0 Members and 1 Guest are viewing this topic.
Offline bitshit

Junior Devvie

Java games rock!!

« Posted 2004-12-06 07:58:03 »

Hi all!

Im expiriencing some thread related problems with an applet game Im writing...

I have 3 threads running: the game thread itself, a keepalive thread that posts a message to the server each x seconds and an sound thread that pulls my musicplayer for sampledata frequently.

I found out that the applet's paint seems to get called by the browser, in certain situations the browser seems to call the applet's repaint in some sort of loop. This caused my sound thread to get too little priority which caused sound stutter. I was able do disable the browser repaints by setting: setIgnoreRepaint(true).

But I had to modify my run method too. Using the sleep() function halved my framerate, thread.yield() resulted in good fps but somehow i loose control after x secs and the whole applet goes beserk. When I call Thread.join(1) it seems to work ok, but I think thats not the proper way of doing this. I thought that join(1) waits 1 ms to kill the thread which doesn't seems to be what i want. Also on slower systems the game thread seems to pause very shortly when I play an audioclip.

How should I implement the thread.yield() properly? It somehow just looses control after a variable period of time...


Offline Jeff

JGO Coder

Got any cats?

« Reply #1 - Posted 2004-12-06 18:42:17 »

Can you describe what you mena by "loses control"?
Exaclty what happens?

Typically in any multi-threaded code, if a sleep 'fixes' your problem then it means you have a race condition somewhere...

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!
Offline bitshit

Junior Devvie

Java games rock!!

« Reply #2 - Posted 2004-12-07 17:54:52 »

I have one sound thread which constantly pulls my music player for sample data and feeds it to the javasound driver. The other thread is the game itself which basicly calls a repaint() followed by a thread.join(1) but which should be a thread.yield i think.

When using thread.yield() :
The game plays ok for about 30 seconds, after that just goes beserk; does not respond to input and it will stutter (sound & graphics). If i press fx the left key, it will respond with a lag of x seconds and seems to kep excecuting that...

When I use thread.join(1) it works ok, but im sure thats not the right way of doing what i want.

a sleep(>20) obviously halfs the framerate but works ok too...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Malohkan

Senior Devvie

while (true) System.out.println("WOO!!!!");

« Reply #3 - Posted 2004-12-08 14:31:32 »

I think we're gonna need to see some of your code to get an idea of why that's happening.  I personally can't think of a reason that your game should be blowing up on you like that.  Show some code and hopefully we can help you track down the problem.

Admin and Game Developer at
Play Rimscape!    |    Play Conquer!
Pages: [1]
  ignore  |  Print  

hadezbladez (2166 views)
2018-11-16 13:46:03

hadezbladez (818 views)
2018-11-16 13:41:33

hadezbladez (2138 views)
2018-11-16 13:35:35

hadezbladez (421 views)
2018-11-16 13:32:03

EgonOlsen (3459 views)
2018-06-10 19:43:48

EgonOlsen (3687 views)
2018-06-10 19:43:44

EgonOlsen (2276 views)
2018-06-10 19:43:20

DesertCoockie (3005 views)
2018-05-13 18:23:11

nelsongames (3085 views)
2018-04-24 18:15:36

nelsongames (3903 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!