OLD | NEW |
(Empty) | |
| 1 package org.adblockplus.android.api; |
| 2 |
| 3 import java.util.concurrent.LinkedBlockingQueue; |
| 4 |
| 5 public final class JniExceptionHandler |
| 6 { |
| 7 private static LogWorker logWorker = null; |
| 8 |
| 9 static |
| 10 { |
| 11 logWorker = new LogWorker(); |
| 12 final Thread t = new Thread(logWorker); |
| 13 t.setDaemon(true); |
| 14 t.start(); |
| 15 } |
| 16 |
| 17 public static void logException(final Throwable t) |
| 18 { |
| 19 logWorker.logException(t); |
| 20 } |
| 21 |
| 22 private final static class LogWorker implements Runnable |
| 23 { |
| 24 LinkedBlockingQueue<Throwable> exceptionQueue = new LinkedBlockingQueue<Thro
wable>(); |
| 25 |
| 26 private void logException(final Throwable t) |
| 27 { |
| 28 this.exceptionQueue.offer(t); |
| 29 } |
| 30 |
| 31 @Override |
| 32 public void run() |
| 33 { |
| 34 for (;;) |
| 35 { |
| 36 try |
| 37 { |
| 38 final Throwable t = this.exceptionQueue.take(); |
| 39 System.err.println("EXCEPTION: " + t); |
| 40 } |
| 41 catch (final InterruptedException ie) |
| 42 { |
| 43 break; |
| 44 } |
| 45 catch (final Throwable ex) |
| 46 { |
| 47 // TODO: Swallow or log? |
| 48 } |
| 49 } |
| 50 } |
| 51 } |
| 52 } |
OLD | NEW |