Original Post
Sometimes in my multithreaded program after starting 2 threads it hangs, although the close button is clickable, but the area inside the window is frozen, and also in Eclipse the little red stop running button is no longer clickable. I'm sure its because the way I'm using the threads. Heres how it goes: -load xml from file into document -start thread to listen for connections --on connection start another thread and receive input there ---add data to xml document ---save document to xml file I put 'volatile' on the variables that are used by multipe threads. eg private volatile Document document; private volatile LogPane logPane = new LogPane(); //just a JPanel with a textarea, and scrollpane And 'synchronized' on the functions that are also used by multiple threads. eg private synchronized void saveDocument(); private synchronized void addSellerToDocument(Node node); private synchronized void onConnection(final Socket socket); Am i handling the accessing of variables and functions from different threads wrongly? thanks edit: Also the series of events is: the first program waits for a connection on a separate thread another program connects, sends data and disconnects the first program creates a another thread to handle the connection, read the sent data and save it to file.