- 性别
- 保密
- 积分
- 100
- 积分
- 351
- 精华
- 6
- 阅读权限
- 100
- 注册时间
- 2013-5-16
- 最后登录
- 2013-11-8
- 帖子
- 43
- 性别
- 保密
|
本帖最后由 liugenhua189 于 2013-6-11 21:10 编辑
共享数据的类
注:ThreadLocal(简单线程)
package org.mybatis.entitys;
public class systemcontext {
private static ThreadLocal<Integer> inoff=new ThreadLocal<Integer>();
private static ThreadLocal<Integer> pagesize=new ThreadLocal<Integer>();
public static int getInoff() {
return inoff.get();
}
public static void setInoff(Integer _inoff) {
inoff.set(_inoff);
}
public static int getPagesize() {
return pagesize.get();
}
public static void setPagesize(Integer _pagesize) {
pagesize.set(_pagesize);
}
}
//为线程共享数据赋值的类(用上一个类的静态方法赋值)
package org.mybatis.entitys;
public class threadparam {
public static void setparam(Integer inoff,Integer pagesize){
systemcontext.setInoff(inoff);
systemcontext.setPagesize(pagesize);
}
}
//打印共享数据信息的类
package org.mybatis.entitys;
public class threadprint {
public static void testprint(){
System.out.println(systemcontext.getInoff()) ;
System.out.println(systemcontext.getPagesize());
}
}
/****测试类**************************************************/
public class test {
public static void main(String[] args) {
threadparam.setparam(34, 45);
threadprint.testprint();
}
}
/********************输出结果***********************************/
34
45
|
|