Sign in to follow this  

Java 1.4 Threads

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

this is a fairly general question with no code examples. I have a program that's a lot like The Game of Life. A grid of squares, or zones, grow to other nearby zones. There are two sets of zones doing this, Red and Blue zones, and when they notice "enemy" zones nearby, they conflict for control of it. Zones are JLabels, which each have a thread to expand. they advance to their surroundings when they change color, and thus change the color of other zones nearby, who each check their neighbors and so on. when a thread is being queried or converted, it locks so no other threads can access it. the program runs well, but after awhile the hundreds of threads running stop and dont destroy. they just stop. there are no loops in any of these threads and they shouldnt be stuck. they will sleep() if a zone is unavailible, and try again... but they are all stopping. What might be wrong to cause hundreds of threads to just stop like that?

Share this post


Link to post
Share on other sites
i'd never try to start hungreds of threads in any system or VM.... and 'd never try to make object-oriented _cells_ for cellular automata/game of life.
edit:because 99.99% of time and space will be wasted,and also i will have to type more text.

Share this post


Link to post
Share on other sites
i agree on using oo for that sort of thing, but the entire experience is actually just a way for me to refresh my memory on threads in java for a new job.

and the system definitely works, they are just dead locking somehow.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Post the code? What if the board fills up? All cells will be blocked, no? What if all cells adjacent to a particular cell are filled. Will the cell in the middle no-op forever?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Threads in Java are not time-slices - there is really no guarantee that any particular thread will run in any given time, and no guarantee that one thread won't run twice as often as another. The exact way your threads behave depends on your hardware, OS and JVM release.

I recommend avoiding threads for something like this. If you want everything to run at the same rate, loop through each object every frame and perform one task each.

In general, wierd thread behaviour is impossible to debug unless you have both the source code, a debugger and access to the computer that is behaving oddly.

--cfmdobbie

Share this post


Link to post
Share on other sites

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this