使用blueprint控制OSGI项目,类不能正常加载问题

public void init() {
        log.debug("------------------------------------------------------------");
        new Thread() {
            @Override
            public void run() {
                super.run();
                try {
                    while (true) {
                        log.debug("--------缓存清理开始扫描。。。。" + new Date());
                        Map<String, CacheUser> cacheUsers = hazelcastClient
                                .getMap(HazelcastConstants.ANTROL_CACHE_USER);
                        log.debug("-----timer start---" + cacheUsers);
                        CacheUser cacheUser = new CacheUser();
                        Iterator<String> valueIterator = cacheUsers.keySet().iterator();
                        String key;
                        while (valueIterator.hasNext()) {
                            key = valueIterator.next();
                            log.debug("-----缓存清理" + key + "。。。。" + new Date());
                            log.debug("-----缓存内是否有值:" + cacheUsers.isEmpty());
                            cacheUser = cacheUsers.get(key);
                            log.debug("-----缓存内容:" + cacheUser);
                            if (null != cacheUser) {
                                long createTime = cacheUser.getCacheCreateTime();
                                log.debug("-----缓存创建时:" + createTime);
                                long nowTime = System.currentTimeMillis();
                                log.debug("-----缓存用时:" + (nowTime - createTime));
                                if (nowTime - createTime > CACHE_OUT_TIME) {
                                    log.debug("-----缓存超时cacheUser:" + cacheUser);
                                    cacheUsers.remove(key);
                                    log.debug("-----缓存超时,清理成功");
                                }
                            }
                        }
                        try {
                            this.sleep(CACHE_INTERVAL_SCAN);
                        } catch (InterruptedException e) {
                            log.error("-----计时器休眠出错", e);
                        }
                    }
                } catch (Exception e) {
                    log.error("-----error", e);
                }
            }
        }.start();
    }

修改后

public void init() {
        ClassLoader bundleClassLoader = getClass().getClassLoader();
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(bundleClassLoader);
        log.debug("------------------------------------------------------------");
        new Thread() {
            @Override
            public void run() {
                super.run();
                try {
                    while (true) {
                        log.debug("--------缓存清理开始扫描。。。。" + new Date());
                        Map<String, CacheUser> cacheUsers = hazelcastClient
                                .getMap(HazelcastConstants.ANTROL_CACHE_USER);
                        log.debug("-----timer start---" + cacheUsers);
                        CacheUser cacheUser = new CacheUser();
                        Iterator<String> valueIterator = cacheUsers.keySet().iterator();
                        String key;
                        while (valueIterator.hasNext()) {
                            key = valueIterator.next();
                            log.debug("-----缓存清理" + key + "。。。。" + new Date());
                            log.debug("-----缓存内是否有值:" + cacheUsers.isEmpty());
                            cacheUser = cacheUsers.get(key);
                            log.debug("-----缓存内容:" + cacheUser);
                            if (null != cacheUser) {
                                long createTime = cacheUser.getCacheCreateTime();
                                log.debug("-----缓存创建时:" + createTime);
                                long nowTime = System.currentTimeMillis();
                                log.debug("-----缓存用时:" + (nowTime - createTime));
                                if (nowTime - createTime > CACHE_OUT_TIME) {
                                    log.debug("-----缓存超时cacheUser:" + cacheUser);
                                    cacheUsers.remove(key);
                                    log.debug("-----缓存超时,清理成功");
                                }
                            }
                        }
                        try {
                            this.sleep(CACHE_INTERVAL_SCAN);
                        } catch (InterruptedException e) {
                            log.error("-----计时器休眠出错", e);
                        }
                    }
                } catch (Exception e) {
                    log.error("-----error", e);
                }
            }
        }.start();
        Thread.currentThread().setContextClassLoader(contextClassLoader);
    }


你可能感兴趣的:(osgi,blueprint,classNotFound,类不能加载)