Hi Forums!!!

I have a question which I would like to pose before posting lots of code. I'll try to be as clear as possible prose. Any help appreciated! System is live and falling over 5 times daily currently.

I have a POS application. I'm wrapping some of the time-consuming client code (Network access to server calls etc) inside a Swingworker class. Everything is running well, but I have a really hard to trace and obscure bug.

The only time I've managed to recreate it is when a swingworker thread makes a call to a Singleton class object (which prints out a customer receipt (inside this customerreceipt class is a thread which watches the cashtill for events. It is this cashtill event trying to tell the server that someone opened the till (via the outputstream) which throws the error))

I;ve taken great pains to try to make sure the Singleton class is thread safe, I used bill pughs solution (post at bottom). If I add Synchronized to the methods in the class it seems to minimize but not alleviate the problem.

The error is "outputstream corrupted(unknown source)". I set up one outputstream inside a "Networkclient.java" class which is my Singleton class. After this error, the outputstream is coput and won't work anymore.

I tried taking the Hashmap() of the class to test if I'm running more than one copy of the singleton, but I only seem to get one hashmap() number. I added a System.out to the constructor reporting creation. So

Can someone explain from this small description what is happening? I can try to make a small example if needed.

Thanks!

public class Singleton {
// Private constructor prevents instantiation from other classes
private Singleton() { }

/**
* SingletonHolder is loaded on the first execution of Singleton.getInstance()
* or the first access to SingletonHolder.INSTANCE, not before.
*/
private static class SingletonHolder {
public static final Singleton instance = new Singleton();
}

public static Singleton getInstance() {
return SingletonHolder.instance;
}
}