Changeset bbb6da2


Ignore:
Timestamp:
Nov 1, 2015 4:47:59 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
787921a
Parents:
b7dc55e3
Message:

cleanups, javadoc

Location:
core/java/src/net/i2p/util
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/util/I2PAppThread.java

    rb7dc55e3 rbbb6da2  
    1515
    1616/**
    17  * Like I2PThread but with per-thread OOM listeners,
     17 * Like {@link I2PThread} but with per-thread OOM listeners,
    1818 * rather than a static router-wide listener list,
    1919 * so that an OOM in an app won't call the router listener
    2020 * to shutdown the whole router.
     21 *
     22 * This is preferred for application use.
     23 * See {@link I2PThread} for features.
    2124 */
    2225public class I2PAppThread extends I2PThread {
  • core/java/src/net/i2p/util/I2PThread.java

    rb7dc55e3 rbbb6da2  
    1515
    1616/**
    17  * In case its useful later...
    18  * (e.g. w/ native programatic thread dumping, etc)
    19  *
    20  * As of 0.9.21, I2PThreads are initialized to NORM_PRIORITY
    21  * (not the priority of the creating thread).
     17 * Preferred over {@link Thread} for all router uses.
     18 * For applications, {@link I2PAppThread} is preferred.
     19 * <p>
     20 * Provides the following features:
     21 * <ul>
     22 * <li>Logging to wrapper log on unexpected termination in {@link #run()}.
     23 * <li>Notification of OOM to registered listener (the router),
     24 *     which will cause logging to the wrapper log and a router restart
     25 * <li>Catching and logging "OOM" caused by thread limit in {@link #start()}
     26 *     with distint message, and does not call the OOM listener.
     27 * <li>As of 0.9.21, initialization to NORM_PRIORITY
     28 *     (not the priority of the creating thread).
     29 * </ul>
    2230 */
    2331public class I2PThread extends Thread {
    24     /**
    25      *  Non-static to avoid refs to old context in Android.
    26      *  Probably should just remove all the logging though.
    27      *  Logging removed, too much trouble with extra contexts
    28      */
    29     //private volatile Log _log;
     32
    3033    private static final Set<OOMEventListener> _listeners = new CopyOnWriteArraySet<OOMEventListener>();
    31     //private String _name;
    32     //private Exception _createdBy;
    3334
    3435    public I2PThread() {
    3536        super();
    3637        setPriority(NORM_PRIORITY);
    37         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    38         //    _createdBy = new Exception("Created by");
    3938    }
    4039
     
    4241        super(name);
    4342        setPriority(NORM_PRIORITY);
    44         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    45         //    _createdBy = new Exception("Created by");
    4643    }
    4744
     
    4946        super(r);
    5047        setPriority(NORM_PRIORITY);
    51         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    52         //    _createdBy = new Exception("Created by");
    5348    }
    5449
     
    5651        super(r, name);
    5752        setPriority(NORM_PRIORITY);
    58         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    59         //    _createdBy = new Exception("Created by");
    6053    }
     54
    6155    public I2PThread(Runnable r, String name, boolean isDaemon) {
    6256        super(r, name);
    6357        setDaemon(isDaemon);
    6458        setPriority(NORM_PRIORITY);
    65         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    66         //    _createdBy = new Exception("Created by");
    6759    }
    6860   
     
    7062        super(g, r);
    7163        setPriority(NORM_PRIORITY);
    72         //if ( (_log == null) || (_log.shouldLog(Log.DEBUG)) )
    73         //    _createdBy = new Exception("Created by");
    7464    }
    7565
     
    8272    }
    8373
    84 /****
    85     private void log(int level, String msg) { log(level, msg, null); }
    86 
    87     private void log(int level, String msg, Throwable t) {
    88         // we cant assume log is created
    89         if (_log == null) _log = new Log(I2PThread.class);
    90         if (_log.shouldLog(level))
    91             _log.log(level, msg, t);
    92     }
    93 ****/
    94    
    9574    /**
    9675     *  Overridden to provide useful info to users on OOM, and to prevent
     
    11897    @Override
    11998    public void run() {
    120         //_name = Thread.currentThread().getName();
    121         //log(Log.INFO, "New thread started" + (isDaemon() ? " (daemon): " : ": ") + _name, _createdBy);
    12299        try {
    123100            super.run();
    124101        } catch (Throwable t) {
    125           /****
    126             try {
    127                 log(Log.CRIT, "Thread terminated unexpectedly: " + getName(), t);
    128             } catch (Throwable woof) {
    129                 System.err.println("Died within the OOM itself");
    130                 t.printStackTrace();
    131             }
    132           ****/
    133102            if (t instanceof OutOfMemoryError) {
    134103                fireOOM((OutOfMemoryError)t);
     
    138107            }
    139108        }
    140         // This creates a new I2PAppContext after it was deleted
    141         // in Router.finalShutdown() via RouterContext.killGlobalContext()
    142         //log(Log.INFO, "Thread finished normally: " + _name);
    143109    }
    144    
    145 /****
    146     protected void finalize() throws Throwable {
    147         //log(Log.DEBUG, "Thread finalized: " + _name);
    148         super.finalize();
    149     }
    150 ****/
    151110   
    152111    protected void fireOOM(OutOfMemoryError oom) {
Note: See TracChangeset for help on using the changeset viewer.