首页 > 编程语言 > 详细

线程、异步

时间:2015-12-01 14:36:20      阅读:264      评论:0      收藏:0      [点我收藏+]

在业务操作时,如有用到数据同步,发送消息等业务,可用线程异步处理实现!

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;


@Service("springUtils")
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext atx;

@Override
public void setApplicationContext(ApplicationContext atx)
throws BeansException {
this.atx = atx;
}

public static ApplicationContext getAtx() {
return atx;
}

public static Object getBean(String beanName) {
return getAtx().getBean(beanName);
}
}

 

用构造函数传参数。

import com.alibaba.fastjson.JSON;
import com.xiexy.project.base.SpringUtils;
import com.xiexy.project.test.service.TestService;


public class SMSThread implements Runnable{

String myName;
String age;

SMSThread(String name,String age) {
myName = name;
this.age=age;
}

@Override
public void run() {

System.out.println(myName+age);
try {
System.out.println("!!!!!!!!!!");
TestService testService=(TestService) SpringUtils.getBean("testService");
System.out.println(JSON.toJSONString(testService.getStations(null)));

} catch (Exception e) {
e.printStackTrace();
}
}
}

 

线程、异步

原文:http://www.cnblogs.com/xiexy/p/5009867.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!