Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4240860
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:13:26+00:00 2026-05-21T03:13:26+00:00

Hi i’m trying to create a sever/client program that takes up to 5 clients

  • 0

Hi i’m trying to create a sever/client program that takes up to 5 clients inputting a string each via multiple server side threads, these strings are to be added to team class ie the Same team, then when the team is full, clients disconnect and the server awaits names for the next Team.

My problem lies in creating an instance of the class Team that each thread updates to..
im not sure where to declare the instance of the class?(it contains a string array[5])
my classes on serverside are currently “TeamServer”, “TeamServerThread” “team” “streamSocket”

Below is my “TeamServerThread” currently taking the user string and just adding it to another string.

import java.io.*;

class TeamServerThread implements Runnable {
    static  String names ="";

   MyStreamSocket myDataSocket;

   TeamServerThread(MyStreamSocket myDataSocket) {
      this.myDataSocket = myDataSocket;
   }

   public void run( ) {
      String newName;
      try {
          newName = myDataSocket.receiveMessage();
/**/      System.out.println("Name Recieved = "+newName);


          updateNames(newName);
          // now send the names to the requestor
          // wait
          myDataSocket.sendMessage(names);
          myDataSocket.close();
      }// end try
      catch (Exception ex) {
           System.out.println("Exception caught in thread: " + ex);
        } // end catch
   } //end run

   private synchronized void updateNames (String newName) {
       names +=newName + "\n";
      // this.team.add(newName);
    } // end updateNames        
} // end Team

Here is my “Team” class

public class Team 
    {
        public final int TEAM_SIZE = 5;

        public String names[] = new String[TEAM_SIZE];
        public int num_members = 0;
        // waits until five names have arrived
        // needs to be synchronized because it can be accessed
        // by a number of concurrent threads

        synchronized void  add(String name) 
        {
            names[num_members] = name;
            num_members++;
            if (num_members < TEAM_SIZE) 
            try 
            {
                wait(); 
            }
            catch(Exception e) {}
            else  
            try 
            {
                notifyAll(); 
            }
            catch(Exception e){}
        } // end add
        public int Getnum_members() 
        { 
            return num_members;
        }



} // end Team 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:13:27+00:00Added an answer on May 21, 2026 at 3:13 am

    All class loading is single threaded and you cannot laod/update a class with multiple threads. However I assume this is not what you mean.

    You need to have the Team where every socket can see it. The problem you have is that you haven’t synchronized access or replacement of the Team so you could ahve a race condition where too many client try to add themselves to the same team.

    I suggest you have some type of TeamCoordinator which is passed to each socket connection which can determine when Team a client should be added to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to loop through a bunch of documents I have to put
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.