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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:52:39+00:00 2026-05-26T14:52:39+00:00

Got a problem about server-client: When server is running, if I want to make

  • 0

Got a problem about server-client:

When server is running, if I want to make some change in ServerThread, for example, the string “Welcome!” to “Hello!”, is that possible to execute that without restart the server? For now, when I change “Welcome!” to something else, it still print out “Welcome!” to client. I have to close eclipse and restart server for this new string working. Is there any way to solve that problem? Thx alot!

Server:

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

public class ATMServer {

    private static int connectionPort = 8989;
    public static void main(String[] args) throws IOException {
    ServerSocket serverSocket = null;
    boolean listening = true; 
    try {
        serverSocket = new ServerSocket(connectionPort); 
    } catch (IOException e) {
        System.err.println("Could not listen on port: " + connectionPort);
        System.exit(1);
    }

    System.out.println("Bank started listening on port: " + connectionPort);
    while (listening)
        new ATMServerThread(serverSocket.accept()).start();
    serverSocket.close();
    }
}

ServerThread:

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

public class ATMServerThread extends Thread {
    private Socket socket = null;
    private BufferedReader in;
    PrintWriter out;
    public ATMServerThread(Socket socket) {
        super("ATMServerThread");
        this.socket = socket;
    }

    public void run(){
    try {
        out = new PrintWriter(socket.getOutputStream(), true);

        out.println("Welcome!"); 

    } catch (IOException e){
        e.printStackTrace();
        }
    }
}

Client:

import java.io.*;   
import java.net.*;  
import java.util.Scanner;

public class Client {
    private static int connectionPort = 8989;

    public static void main(String[] args) throws IOException {

        Socket ATMSocket = null;
        PrintWriter out = null;
        BufferedReader in = null;
        String adress = "";

        try {
            adress = "127.0.0.1";
        } catch (ArrayIndexOutOfBoundsException e) {
            System.err.println("Missing argument ip-adress");
            System.exit(1);
        }
        try {
            ATMSocket = new Socket(adress, connectionPort); 
            out = new PrintWriter(ATMSocket.getOutputStream(), true);
            in = new BufferedReader(new InputStreamReader
                                    (ATMSocket.getInputStream()));
        } catch (UnknownHostException e) {
            System.err.println("Unknown host: " +adress);
            System.exit(1);
        } catch (IOException e) {
            System.err.println("Couldn't open connection to " + adress);
            System.exit(1);
        }

        System.out.println(in.readLine());


        out.close();
        in.close();
        ATMSocket.close();
    }
}
  • 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-26T14:52:40+00:00Added an answer on May 26, 2026 at 2:52 pm

    This is possible but not simple.

    The string “Welcome!” is part of the class file (it’s a static String constant). When you change it, Eclipse will create a new .class file and write that to disk.

    At the same time, you have a running Java program which uses the same .class file. There are two reasons why the change isn’t picked up:

    1. A Java VM doesn’t reload class files by itself. When a class has been loaded once, it doesn’t update when you change the .class file on the disk. You have to tell the classloader to flush the loaded class from memory and load the .class file again.

    2. There is an instance of this class in the running VM. The instance has a reference to a String object. Even when the class is loaded again, this instance (and its references) don’t change. You have to create a new instance.

    To fix the first problem, you need to run your application in Debug mode. Eclipse will then try to tell the VM when .class files have changed. Note that some changes can’t be reloaded by some VMs. For example, Sun’s VM can handle new methods, method parameters, fields, imports. You can only change method bodies. Eclipse will tell you when the reload has failed.

    To fix the second issue, stop the thread and start a new one. I suggest a special client “restart” message for this which stops all threads and creates a new pool.

    In any case, it’s never necessary to stop Eclipse.

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

Sidebar

Related Questions

Earlier I got some great advice about Client/server sockets in c . I have
Recently, I've started having a problem with my SQL Server 2005 client running on
I've got a problem about onbeforeunload recently that I need to pop up a
I have got a strange problem about in_array recently which I cannot understand. e.g.
I have got a performance problem about TextField.htmlText +=msg .And I know that TextField.appendText(msg)
I've hit an annoying problem in LaTeX. I've got a tex file of about
I am after so advice really. I have been thinking about a client server
I got a big problem this morning. My SQL Server had a HUGE bug
I've got a client/server setup that I am implementing using a WCF Service (
Calling all Oracle heads, I've got a weird problem with a sql query... Running

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.