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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:07:45+00:00 2026-06-15T12:07:45+00:00

I’m simply trying to send a message to another object but its not exactly

  • 0

I’m simply trying to send a message to another object but its not exactly changing unless I’m missing a important factor. I have one class to set the number and another class which gets, the class that gets is dependent on the correct number being set however although the set method returns 0 one the command line, the other object returns 1 when using the get method. This is the close class whihc holds both of the methods, each method is called from class A and Class B

public class Close {
    static int close =1;

    public synchronized void setClose(int x, Client)
    {
        /*
        while(turn !=0){
            try{
                wait();

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }*/
        close = x;
        System.out.println("set "+close);
    }

    public synchronized int getClose(ClientHandeler)
    {
        int x;
        /*
        while(turn==0){
            try{
                wait();
            }catch(Exception e)
            }
        }*/
        System.out.println("get "+close);
        x = close;
        return x;
    }

}

This is the handler class in which i wish to get the close integer from

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

public class ClientHandler implements Runnable {

private BufferedReader reader;
private Socket sock;//refering to socket class
//listens for the socket
private Server server; // call-back reference to transmit message to all clients
Client c = new Client();

public ClientHandler(Socket clientSocket, Server serv) {

    try {
            sock = clientSocket;
            server = serv;

            InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
            reader = new BufferedReader(isReader);



     } catch (Exception ex) {
         ex.printStackTrace();
     }
}

public void run() {

    String message;




    try {

         int x = c.c.getClose(this);
         while(x!=0){
         x = c.c.getClose(this);//calls client and within client there is the close 
            System.out.println(x);

            Thread ct= Thread.currentThread();
            ct.sleep(3000);
            while ((message = reader.readLine()) != null) {

                System.out.println("read " + message);

                server.tellEveryone(message);
            }
        }       
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}





}
  • 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-15T12:07:48+00:00Added an answer on June 15, 2026 at 12:07 pm

    Probably they both do not use the same Close object.

    Close close = new Close();
    

    Then make sure that both use the same close object!

    If that is not possible, field close can be made static:

      public class Close {
    static int close;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms

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.