|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#61
|
||||
|
||||
|
So I'm looking for a bit of advice.
I have several threads. Since these need to keep running forever, or until stuff is shut off, there are infinite loops. Well, wouldn't you know it, that makes my simple little console app eat CPU like Oprah eats cheesecake. What would be much better is if the thread could block until it was needed again. Instead of constantly doing stuff (looping), it should do nothing until it needs to. I'm going to google it and post back if I get a good solution.
__________________
A work in progress: Card Game Platform (Status: Hard Drive Crash deleted project, rewrite planned) | Joke Thread “Rational thinkers deplore the excesses of democracy; it abuses the individual and elevates the mob. The death of Socrates was its finest fruit.” |
|
#62
|
||||
|
||||
|
Setup a system of checks. If A is doing X, have B do Y. Otherwise have B sleep for Z seconds. Of course, there is probably a better solution, so keep looking.
__________________
"Java makes impossible things possible, but makes easy things difficult." - Somebody
|
|
#63
|
||||
|
||||
|
You up to speed with semaphores for interprocess communications?
__________________
--Ax without exception, there is no rule ... The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones ![]() 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ... |
|
#64
|
||||
|
||||
|
Quote:
|
|
#65
|
||||
|
||||
|
Makes one wish for a good OS where one can relinquish one's time slice.
If you have a lot of threads that do nothing for a lot of the time, perhaps you should reconsider your approach. Spawn a thread when you need it, grab the results, and kill it. |
|
#66
|
||||
|
||||
|
Quote:
'twas only a temporary suggestion, until you could come up with a better solution. Sleep uses up no CPU time, so it would work perfectly to reduce stress on the CPU. If sizablegins solution doesn't suit you, maybe try something like THIS? |
|
#67
|
|||||
|
|||||
|
As I said, I think I got something. To be perfectly honest, almost all 'advice' you have given me absolutely does not help. Please review your posts and see for yourself. And have at least some server/client experience before telling me how to do things. This is a soft rebuke, but mostly asking you to know before speaking. The link you provided me is some very unsafe coding that might just work if it was what I wanted. Incidentally, a 1-second glance through the API had already told me that a long time ago.
Wei: I really don't have that many. One thread for every user. One processing thread. One thread for each game. With 10 users and 10 games (of solitaire?) I'd have 21 threads. With 20 people and 5 games of setback, I'd have 26 threads. Too many? The thing is, I know my server can handle it. I've made it have over 25 threads at a time and it didn't balk. My problem is that it consumes all the CPU it can, no matter whether there are 20 people connected or none. Take a look: Driver class creates Server class. The Server controls everything else. Take a look at Server's constructor. More importantly, take a look at the try{} block. That's why it'll eat all CPU it can get even without users connected. JAVA Code:
|
|
#68
|
||||
|
||||
|
Maybe it's time to move this over to the Java forum? ...
|
|
#69
|
||||
|