Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>public void waitForConnection() throws IOException { connection = server.accept(); ConnectionArray.add(connection); ConnectionHandler connections = new ConnectionHandler(connection); connection = null; } </code></pre> <p><code>connection</code> is not found, so either this is not the actual code, or you are storing this temporary variable in a member or global. In either case, increasing the scope of temporary variables to span different functions is bad, with multiple threads its like juggling chainsaws. BTW: It would be more natural to store the connection handlers in a list than creating them and storing their sockets in a list. This is a case where the responsibilities are unclear, leading to unclear and buggy code.</p> <p>While the above case could be harmless still, it still shows bad and dangerous style. You keep on with this style (at least it's consistent!) with "...it takes a socket X and sets it to the global socket as shown...":</p> <pre><code>static Socket Socket; public ConnectionHandler(Socket X) { this.Socket = X; } </code></pre> <p>Making <code>Socket Socket</code> static, it is shared between all instances of this class, which is obviously not what you want. You should now know why globals are considered bad and why class-statics are only globals in disguise.</p> <p>Summary: Decide who accesses which parts. If it's just one object, make the parts private members, so the compiler makes sure it's really only one object. Try not to share state. If multiple objects and threads access an object, plan how they don't get in each others way.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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