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

  • SEARCH
  • Home
  • 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 7586691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:29:20+00:00 2026-05-30T19:29:20+00:00

I am trying to setup my MessageServer class so that it services each client

  • 0

I am trying to setup my MessageServer class so that it services each client in a separate request (you’ll see below that it’s pretty linear right now)

How should I go about it?

import java.net.*;
import java.io.*;

public class MessageServer {

public static final int PORT = 6100;

public static void main(String[] args) {

    Socket client = null;
    ServerSocket sock = null;
    BufferedReader reader = null;

    try {
        sock = new ServerSocket(PORT);
        // now listen for connections
        while (true) {
            client = sock.accept();

            reader = new BufferedReader(new InputStreamReader(client.getInputStream()));

            Message message = new MessageImpl(reader.readLine());

            // set the appropriate character counts
            message.setCounts();

            // now serialize the object and write it to the socket
            ObjectOutputStream soos = new ObjectOutputStream(client.getOutputStream());
            soos.writeObject(message);
            System.out.println("wrote message to the socket");

            client.close();
        }
    }
    catch (IOException ioe) {
            System.err.println(ioe);
    }


}

}

  • 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-30T19:29:21+00:00Added an answer on May 30, 2026 at 7:29 pm

    Sorry, but your question doesn’t make much sense.

    If we are using the term “request” in the normal way, a client sends a request to the server and the server processes each request. It simply makes no sense for a server to not service the requests separately (in some sense).

    Perhaps you are asking something different. (Do you mean, “service each client request in a separate thread”?) Whatever you mean, please review your terminology.


    Given that you are talking about executing requests in different threads, then using the ExecutorService API is a good choice. Use an implementation class that allows you to put an upper bound on the number of worker threads. If you don’t, you open yourself up for problems where overload results in the allocation of large numbers of threads, which only makes the server slower. (Besides, creating new threads is not cheap. It pays to recycle them.)

    You should also consider configuring your executor so that it doesn’t have a request queue. You want the executor service to block the thread that is trying to submit the job if there isn’t a worker available. Let the operating system queue incoming connections / requests at the ServerSocket level. If you queue requests internally, you can run into the situation where you are wasting time by processing requests that the client-side has already timed out / abandoned.

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

Sidebar

Related Questions

I'm trying setup a map that displays different pin colors depending on the type/class
After trying to setup my site for Google Webmaster Tools I found that my
I'm trying to setup a loop in Wordpress that will show all posts from
I'm trying to setup a Python application that should automatically start when Linux boots.
Trying to setup a SQL stored procedure that if the variable passed to it
Trying to setup a Cron task that gets a file via FTP however seems
Im trying to setup a simple environment: class Member < ActiveRecord::Base has_many :microposts, :dependent
I am trying to setup an activity in Android that has 50% of the
I'm trying to setup a django app that allows me to store and lookup
Im trying to setup a program that will accept an incoming email and then

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.