- reader = new Reader(s, pending);
- writer = new Writer(s, queue, pending);
- Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
- public void uncaughtException(Thread t, Throwable c) {
- boolean n = false;
- if(c instanceof StopCondition) {
- StopCondition s = (StopCondition)c;
- n = s.normal;
- c = s.getCause();
- }
- Exception e;
- if(c instanceof Exception)
- e = (Exception)c;
- else
- e = new Exception(c);
- if(!n) {
- close();
- error = e;
- }
- synchronized(pending) {
- Command cmd;
- while((cmd = pending.poll()) != null) {
- cmd.error(e);
- }
- }
- synchronized(queue) {
- Command cmd;
- while((cmd = queue.poll()) != null) {
- cmd.error(e);
- }
- }
- }
- };
- reader.setUncaughtExceptionHandler(h);
- writer.setUncaughtExceptionHandler(h);