Idle thread in multithreading socket program.
Okay, so basically I am making a server. That has a structure like this:
- A thread that accepts connections.
- A thread that logs a player in. (It's a game)
- And a thread that connects to a "Friends server". This server holds data of all online players. (used for chatting between different servers (worlds)).
Now my question is; how can I make the thread, that is connected to the friends server, idle. So when a new player logs in, I can directly send a packet to the friends server that holds the player's name and world with just one method ( FriendsServerConnector.getConnector().updatePlayer s(String name) ), without letting the thread stop (which it already did, after the socket passed the connection protocol)
I hope my question is clear.
Endian.
Re: Idle thread in multithreading program.
Not sure what you mean by "idle". There are many ways to block/suspend execution of a thread.
For example the wait() method.
Re: Idle thread in multithreading program.
Quote:
Originally Posted by
Norm
Not sure what you mean by "idle". There are many ways to block/suspend execution of a thread.
For example the wait() method.
Yeah, I know that method, but I get a IlligalMonitorStateException, could this happen because of the singleton pattern?
And with idle I mean a thread that does nothing but still runs.
Re: Idle thread in multithreading program.
Did you read the API doc for that exception? Are you doing the thing it is thrown for?
Not sure what you mean by "idle" and "still runs"
Re: Idle thread in multithreading program.
Quote:
Originally Posted by
Norm
Did you read the API doc for that exception? Are you doing the thing it is thrown for?
Not sure what you mean by "idle" and "still runs"
Look, I have a 'main' thread that is constantly checking for connections. When a new connection is found and the connection has taken off the login protocol it the main thread sends the player's name to the 'friends server', this connection to the friends server is established when I run the server. But after that that thread just stops and discards all the objects (socket, out/input streams), so I have to keep it running.
But I think I don't really understand the wait() method yet, I'll look into the docs and examples.
Re: Idle thread in multithreading program.
Quote:
after that that thread just stops
What does "stops" mean?
The run method exits killing the thread and requiring a new thread to be created
or the thread blocks waiting for an event
or ???