Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Idle thread in multithreading program.

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    My Mood
    Sleepy
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default 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.
    Last edited by Endian; May 13th, 2012 at 02:15 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    My Mood
    Sleepy
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: Idle thread in multithreading program.

    Quote Originally Posted by Norm View Post
    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.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default 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"
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    8
    My Mood
    Sleepy
    Thanks
    0
    Thanked 2 Times in 1 Post

    Default Re: Idle thread in multithreading program.

    Quote Originally Posted by Norm View Post
    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.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Idle thread in multithreading program.

    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 ???
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Multithreading / Multiple Connections
    By Spicyfish in forum Java Networking
    Replies: 21
    Last Post: August 11th, 2012, 01:21 AM
  2. Java Multithreading Example - Issues
    By vijayinani in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 30th, 2012, 10:46 AM
  3. Multithreading in java
    By skillet in forum Java Theory & Questions
    Replies: 1
    Last Post: March 17th, 2012, 07:32 AM
  4. Multithreading and its importance in java
    By jessie143143 in forum The Cafe
    Replies: 0
    Last Post: October 13th, 2011, 02:09 PM
  5. Replies: 1
    Last Post: April 1st, 2009, 02:47 PM