Results 1 to 7 of 7
- 08-17-2011, 05:52 PM #1
Are there problems with massive amounts of threads
What problems come with having a bunch of classes and objects with their own threads running at the same time(Game class, Player class, Item class, terrain class all have their own threads)? For example, I have an Item class that has its own thread that detects if the player has intercepted its bounding box/Rectangular area. Right now, there does not seem to be a problem because I only have two Items on the screen. But what happens when I need 50 or 100 items (hypothetically). Is there an issue with having 100 threads running at the same time or does Java have some really awesome way of handling them and I do not have to worry about the amount of threads I have running.
Thank you for listening.My API:Java Code:cat > a.out || cat > main.class
- 08-17-2011, 06:01 PM #2
I'm not sure what the performance hit would be with 100s of threads. I might redesign the app to use just a few threads. One thread could move all of the objects and test them all for collisions.
-
You will probably want to use a thread pool with a fixed number of threads so as not to overwhelm the system.
- 08-18-2011, 03:58 PM #4
Hmmm, Is there a way to get one class that use the Thread of another class. I would like to know if I could get my Item class to use Game's thread but have Item invoke run() from it's class rather than code Game to invoke a method in Item using run(), if that makes sense. I am not too sure this is even possible. If not, I can always come up with something else.
My API:Java Code:cat > a.out || cat > main.class
- 08-18-2011, 04:11 PM #5
It's not class's that use Threads, its methods.way to get one class that use the Thread of another class.
If you call a method, that method is running on your thread. So if a method in "another class" calls a method in "one class" then that method is using the "another class"s method's thread.
- 08-18-2011, 04:21 PM #6
Another way to think of the problem:
There is a continuing supply of new events that are to take place sometime in the future. If these events were wrapped in a class and put on a list ordered by the time in the future when the event is to occur, then you could have one controlling thread that services this list. It would look at the time of the next event and set a timer to restart itself when the time comes for the event to happen. When the timer calls the control program it awakens and executes all the events due to be executed at that time, then looks at the time for the next event, sets a timer to wait until the time for that event to be executed. And so on.
The event's methods would be putting new events on the queue scheduled to be executed some time in the future.
- 08-19-2011, 05:00 AM #7
Similar Threads
-
problems with threads in my program (runnable)
By runn81 in forum Threads and SynchronizationReplies: 12Last Post: 05-09-2011, 05:26 PM -
BankAccount, how to reject negative amounts? PLEASE HELP!
By armedrabbit in forum New To JavaReplies: 6Last Post: 03-07-2011, 03:12 AM -
Is there a way to speed up these Threads? (Rendering Problems)
By anro in forum Advanced JavaReplies: 4Last Post: 09-30-2009, 09:49 AM -
Help with a massive problem
By jolt in forum New To JavaReplies: 2Last Post: 02-25-2009, 06:51 PM -
Massive Hit Deletion Help please
By quickfingers in forum Java 2DReplies: 1Last Post: 12-24-2007, 07:49 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks