Changeset 1f3f17c


Ignore:
Timestamp:
Jul 4, 2011 4:13:28 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
435683c
Parents:
d4b2805
Message:
  • PeerManager?: Load profiles in separate thread to avoid slowing

down the context initAll()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/peermanager/PeerManager.java

    rd4b2805 r1f3f17c  
    5454   
    5555    /**
    56      *  Warning - this loads all the profiles in the constructor.
    57      *  This may take a long time - 30 seconds or more.
    58      *  Instantiate this in a Job or Thread.
     56     *  Profiles are now loaded in a separate thread,
     57     *  so this should return quickly.
    5958     */
    6059    public PeerManager(RouterContext context) {
     
    6867        for (int i = 0; i < _peersByCapability.length; i++)
    6968            _peersByCapability[i] = new ConcurrentHashSet();
    70         loadProfiles();
     69        loadProfilesInBackground();
    7170        ////_context.jobQueue().addJob(new EvaluateProfilesJob(_context));
    7271        //SimpleScheduler.getInstance().addPeriodicEvent(new Reorg(), 0, REORGANIZE_TIME);
    73         new Reorg();
     72        //new Reorg();
    7473        //_context.jobQueue().addJob(new PersistProfilesJob(_context, this));
    7574    }
     
    123122        if (true)
    124123            _persistenceHelper.writeProfile(prof);
     124    }
     125
     126    /**
     127     *  Load the profiles in a separate thread, so we don't spend
     128     *  forever in the constructor (slowing down the Router constructor
     129     *  via RouterContext.initAll()).
     130     *  This also instantiates Reorg, so only call this once
     131     *
     132     *  @since 0.8.8
     133     */
     134    private void loadProfilesInBackground() {
     135        (new Thread(new ProfileLoader())).start();
     136    }
     137
     138    /**
     139     *  Load the profiles and instantiate Reorg
     140     *
     141     *  @since 0.8.8
     142     */
     143    private class ProfileLoader implements Runnable {
     144        public void run() {
     145            loadProfiles();
     146            new Reorg();
     147        }
    125148    }
    126149
Note: See TracChangeset for help on using the changeset viewer.