Note that there are some explanatory texts on larger screens.

plurals
  1. POset and get method not working as planned
    text
    copied!<p>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</p> <pre><code>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; } } </code></pre> <p>This is the handler class in which i wish to get the close integer from</p> <pre><code>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(); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload