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 8025539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:11:45+00:00 2026-06-04T23:11:45+00:00

There is need to create a new thread for each connection. Thread should have

  • 0

There is need to create a new thread for each connection. Thread should have function to write to socket even if it is in run() waiting for client input: String clientCommand = in.readLine(). The function update should meet this requirements and be able to write to socket using PrintWriter outWr but it seems to be null, even if setting it in thread constructor.
Cannot initialize PrintWriter outWr in constructor. After try construction outWr remains to be null. How to fix it?


public class Server {
    public static void main(String[] args) { 
        ...
        ClientServiceThread cliThread = new ClientServiceThread(clientSocket, id++, auction);
        ...
}

public class ClientServiceThread extends Thread  {
private PrintWriter outWr;

ClientServiceThread(Socket s, int clientID, Auction a) {
        try {
            PrintWriter outWr = new PrintWriter(new OutputStreamWriter(
                    m_clientSocket.getOutputStream()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public void run() {....; String clientCommand = in.readLine(); ... }
public void update(String msg){outWr.println(msg);}
  • 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-06-04T23:11:46+00:00Added an answer on June 4, 2026 at 11:11 pm

    Look at this code

    public class ClientServiceThread extends Thread  {
    private PrintWriter outWr;
    
    ClientServiceThread(Socket s, int clientID, Auction a) {
            try {
                PrintWriter outWr = new PrintWriter(new OutputStreamWriter(
    

    In constructor you do not initialize class field but local reference PrintWriter outWr

    Change it to

            try {
                outWr = new PrintWriter(new OutputStreamWriter(
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to create multiple processing threads in a new application. Each
I have the following three arrays and need to create a new two-dimensional array
I need to know if it is possible to create a new thread to
I am new to Zkoss and i need to create completely new css theme
I need to create a simple blog site where there are blogposts, users and
We need to create a basic PDF reader running on J2ME. While there are
I need to know if there is a way to create a custom shortcut
I have a some computation program. Now, this program is a single-thread, I need
I have a multithreaded program where I create a generator function and then pass
I need to run 5 algorithms parallely each takes an image as input and

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.