欢迎来到天天文库
浏览记录
ID:11456911
大小:19.34 KB
页数:6页
时间:2018-07-12
《线程上下文threadcontext》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、importjava.util.ArrayList; importjava.util.HashMap; importjava.util.List; importjava.util.Map; importorg.osgi.framework.Bundle; importorg.osgi.framework.BundleEvent; importorg.osgi.framework.BundleListener; importcom.quickwebframework.entity.Log; imp
2、ortcom.quickwebframework.entity.LogFactory; publicabstractclassThreadContext{ privatestaticLoglog=LogFactory.getLog(ThreadContext.class); publicstaticvoidinit(){ finalBundlecoreBundle=FrameworkContext.coreBundle; coreBundle.ge
3、tBundleContext().addBundleListener(newBundleListener(){ @Override publicvoidbundleChanged(BundleEventarg0){ inteventType=arg0.getType(); Bundlebundle=arg0.getBundle(); //如果插件的状态是正在停止或已经停止 if(eventType==BundleEvent.STOPPE
4、D
5、
6、eventType==BundleEvent.STOPPING){ if(bundle.equals(coreBundle)){ removeAllFilter(); }else{ removeBundleAllThread(bundle); } }
7、 } }); } privatestaticListthreadList=newArrayList(); privatestaticMap>bundleThreadListMap=newHashMap>(); /** *得到线程列表 * *@return */ publicstat
8、icListgetThreadList(){ returnthreadList; } /** *移除所有的线程 */ publicstaticvoidremoveAllFilter(){ for(Bundlebundle:bundleThreadListMap.keySet() .toArray(newBundle[0])){ removeBundle
9、AllThread(bundle); } } /** *移除某Bundle所有的线程 * *@parambundle */ publicstaticvoidremoveBundleAllThread(Bundlebundle){ if(!bundleThreadListMap.containsKey(bundle)) return; Thread[]bundleT
10、hreadArray=bundleThreadListMap.get(bundle).toArray( newThread[0]); for(Threadthread:bundleThreadArray){ removeThread(bundle,thread); } bundleThreadListMap.remove(bundle); } /
此文档下载收益归作者所有