Results 1 to 1 of 1
- 01-31-2012, 11:41 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 7
- Rep Power
- 0
Threads and Swingworkers and Objectoutputstream
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;
}
}
Similar Threads
-
ResultSet through ObjectOutputStream
By FlyNn in forum Advanced JavaReplies: 4Last Post: 03-07-2011, 08:16 PM -
How does ObjectOutputStream access private writeObject(ObjectOutputStream) methods?
By kreyszig in forum Advanced JavaReplies: 17Last Post: 10-14-2010, 11:26 PM -
Multiple SwingWorkers
By Arne in forum Threads and SynchronizationReplies: 12Last Post: 08-26-2010, 03:54 AM -
ObjectOutputStream Example
By Java Tip in forum Java TipReplies: 0Last Post: 03-20-2008, 10:21 AM -
question on ObjectOutputStream
By money123 in forum New To JavaReplies: 5Last Post: 07-27-2007, 11:31 AM
Bookmarks