程序员@老李 https://blog.mostion.com/ 左手代码右手烟,记录代码人生! SpringBoot静态方法调用Spring容器bean的几种方案 https://blog.mostion.com/archives/49/ 2023-12-14T13:47:13+08:00 今天遇到一个问题,需要在静态方法中调用哦那个容器Bean,大致代码如下:@Autowired private static RedisUtil redisUtilBean; public static String getMsgByRedis(){ redisUtilBean.get("xxx") //这里redisUtilBean一定会是NULL值 }为什么会出现这种情况?原因是Spring容器的依赖注入是依赖set方法,而set方法是实例对象的方法,注入依赖时是无法注入静态成员变量的,在调用的时候依赖的Bean才会为null;解决方案一使用@PostConstruct注解:@Autowired private RedisUtil redisUtilBean; //由于静态方法无法使用注入的Bean 定义静态变量 private static RedisUtil redisUtil; //当容器实例化当前受管Bean时@PostConstruct注解的方法会被自动触发,借此来实现静态变量初始化 @PostConstruct public void init(){ this.redisUtil = redisUtilBean; } public static String getMsgByRedis(){ redisUtil.get("xxx") //这里可以正常使用 }解决方案二利用springboot的启动类中,SpringApplication.run() 方法返回的是一个ConfigurableApplicationContext对象通过定义static变量ConfigurableApplicationContext,利用容器的getBean方法获得依赖对象;@SpringBootApplication @EnableTransactionManagement public class Application { //定义静态的ApplicationContext public static ConfigurableApplicationContext applicationContext; public static void main(String[] args) { applicationContext = SpringApplication.run(Application.class, args); } } //调用 注意Application是我们SpringBoot的启动类 public static String getMsgByRedis(){ Application.applicationContext.getBean(RedisUtil .class).get("xxx") }解决方案三在我们以前SpringMVC中常用的工具类,通过实现ApplicationContextAware接口,网上也很多这里就把工具类贴出来即可;/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.toher.common.utils.spring; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; import java.util.Map; /** * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候中取出ApplicaitonContext. * * @author 李怀明 * @version 2017-01-02 */ @Component public class SpringContextHolder implements ApplicationContextAware { private static ApplicationContext applicationContext; //实现ApplicationContextAware接口的context注入函数, 将其存入静态变量. public void setApplicationContext(ApplicationContext applicationContext) { SpringContextHolder.applicationContext = applicationContext; } //取得存储在静态变量中的ApplicationContext. public static ApplicationContext getApplicationContext() { checkApplicationContext(); return applicationContext; } //从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. @SuppressWarnings("unchecked") public static <T> T getBean(String name) { checkApplicationContext(); return (T) applicationContext.getBean(name); } //从静态变量ApplicationContext中取得Bean, 自动转型为所赋值对象的类型. //如果有多个Bean符合Class, 取出第一个. @SuppressWarnings("unchecked") public static <T> T getBean(Class<T> clazz) { checkApplicationContext(); @SuppressWarnings("rawtypes") Map beanMaps = applicationContext.getBeansOfType(clazz); if (beanMaps != null && !beanMaps.isEmpty()) { return (T) beanMaps.values().iterator().next(); } else { return null; } } private static void checkApplicationContext() { if (applicationContext == null) { throw new IllegalStateException("applicaitonContext未注入,请在applicationContext.xml中定义SpringContextHolder"); } } public static HttpServletRequest getRequest() { try { return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); } catch (Exception e) { return null; } } } 调用方法:RedisUtil redisUtil= (RedisUtil) SpringContextHolder.getBean(RedisUtil.class);结束,感谢! SpringBoot 自定义线程池 https://blog.mostion.com/archives/48/ 2023-11-29T08:51:00+08:00 我们都知道spring只是为我们简单的处理线程池,每次用到线程总会new 一个新的线程,效率不高,所以我们需要自定义一个线程池。本教程目录:自定义线程池配置spring默认的线程池1. 自定义线程池1.1 修改application.propertiestask.pool.corePoolSize=20 task.pool.maxPoolSize=40 task.pool.keepAliveSeconds=300 task.pool.queueCapacity=501.2 线程池配置属性类TaskThreadPoolConfig.javaimport org.springframework.boot.context.properties.ConfigurationProperties; /** * 线程池配置属性类 * Created by Fant.J. */ @ConfigurationProperties(prefix = "task.pool") public class TaskThreadPoolConfig { private int corePoolSize; private int maxPoolSize; private int keepAliveSeconds; private int queueCapacity; ...getter and setter methods... }1.3 创建线程池 TaskExecutePool.java/** * 创建线程池 * Created by Fant.J. */ @Configuration @EnableAsync public class TaskExecutePool { @Autowired private TaskThreadPoolConfig config; @Bean public Executor myTaskAsyncPool() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); //核心线程池大小 executor.setCorePoolSize(config.getCorePoolSize()); //最大线程数 executor.setMaxPoolSize(config.getMaxPoolSize()); //队列容量 executor.setQueueCapacity(config.getQueueCapacity()); //活跃时间 executor.setKeepAliveSeconds(config.getKeepAliveSeconds()); //线程名字前缀 executor.setThreadNamePrefix("MyExecutor-"); // setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务 // CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor; } }1.4 创建线程任务/** * Created by Fant.J. */ @Component public class AsyncTask { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Async("myTaskAsyncPool") //myTaskAsynPool即配置线程池的方法名,此处如果不写自定义线程池的方法名,会使用默认的线程池 public void doTask1(int i) throws InterruptedException{ logger.info("Task"+i+" started."); } }1.5 修改启动类给启动类添加注解@EnableAsync @EnableConfigurationProperties({TaskThreadPoolConfig.class} ) // 开启配置属性支持1.6 测试protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Autowired private AsyncTask asyncTask; @Test public void AsyncTaskTest() throws InterruptedException, ExecutionException { for (int i = 0; i < 100; i++) { asyncTask.doTask1(i); } logger.info("All tasks finished."); }2. 配置默认的线程池我本人喜欢用这种方式的线程池,因为上面的那个线程池使用时候总要加注解@Async("myTaskAsyncPool"),而这种重写spring默认线程池的方式使用的时候,只需要加@Async注解就可以,不用去声明线程池类。2.1 获取属性配置类这个和上面的TaskThreadPoolConfig类相同,这里不重复2.2 NativeAsyncTaskExecutePool.java 装配线程池/** * 原生(Spring)异步任务线程池装配类 * Created by Fant.J. */ @Slf4j @Configuration public class NativeAsyncTaskExecutePool implements AsyncConfigurer{ //注入配置类 @Autowired TaskThreadPoolConfig config; @Override public Executor getAsyncExecutor() { ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); //核心线程池大小 executor.setCorePoolSize(config.getCorePoolSize()); //最大线程数 executor.setMaxPoolSize(config.getMaxPoolSize()); //队列容量 executor.setQueueCapacity(config.getQueueCapacity()); //活跃时间 executor.setKeepAliveSeconds(config.getKeepAliveSeconds()); //线程名字前缀 executor.setThreadNamePrefix("MyExecutor-"); // setRejectedExecutionHandler:当pool已经达到max size的时候,如何处理新任务 // CallerRunsPolicy:不在新线程中执行任务,而是由调用者所在的线程来执行 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); executor.initialize(); return executor; } /** * 异步任务中异常处理 * @return */ @Override public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return new AsyncUncaughtExceptionHandler() { @Override public void handleUncaughtException(Throwable arg0, Method arg1, Object... arg2) { log.error("=========================="+arg0.getMessage()+"=======================", arg0); log.error("exception method:"+arg1.getName()); } }; } }2.3 线程任务类AsyncTask .java@Component public class AsyncTask { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Async public void doTask2(int i) throws InterruptedException{ logger.info("Task2-Native"+i+" started."); } }2.4 测试@Test public void AsyncTaskNativeTest() throws InterruptedException, ExecutionException { for (int i = 0; i < 100; i++) { asyncTask.doTask2(i); } logger.info("All tasks finished."); } 2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-8] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native6 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-3] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native1 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native7 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native21 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native22 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native23 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native24 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native25 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native26 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native27 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native28 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native29 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native30 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native31 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native32 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native33 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native34 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native35 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native36 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native37 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native38 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native39 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native40 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native41 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native42 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native43 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native44 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native45 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native46 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native47 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-7] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native5 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-7] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native49 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-7] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native50 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-11] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native9 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native4 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native53 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native54 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native55 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native56 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native57 started.2018-03-25 21:23:07.659 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native58 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native59 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native60 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native61 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native62 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native63 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native64 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native65 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native66 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native67 started.2018-03-25 21:23:07.660 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native68 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-5] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native3 started.2018-03-25 21:23:07.655 INFO 4668 --- [ MyExecutor-4] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native2 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-8] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native19 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-2] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native0 started.2018-03-25 21:23:07.656 INFO 4668 --- [ MyExecutor-3] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native20 started.2018-03-25 21:23:07.657 INFO 4668 --- [ MyExecutor-10] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native8 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native48 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-7] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native51 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-11] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native52 started.2018-03-25 21:23:07.658 INFO 4668 --- [ MyExecutor-12] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native10 started.2018-03-25 21:23:07.661 INFO 4668 --- [ MyExecutor-13] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native11 started.2018-03-25 21:23:07.662 INFO 4668 --- [ MyExecutor-14] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native12 started.2018-03-25 21:23:07.662 INFO 4668 --- [ MyExecutor-15] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native13 started.2018-03-25 21:23:07.663 INFO 4668 --- [ MyExecutor-16] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native14 started.2018-03-25 21:23:07.663 INFO 4668 --- [ MyExecutor-17] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native15 started.2018-03-25 21:23:07.663 INFO 4668 --- [ MyExecutor-18] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native16 started.2018-03-25 21:23:07.663 INFO 4668 --- [ MyExecutor-19] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native17 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-20] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native18 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-21] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native69 started.2018-03-25 21:23:07.664 INFO 4668 --- [ main] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native89 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-6] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native90 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-22] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native70 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-5] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native91 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-5] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native92 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-8] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native93 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-2] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native94 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-10] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native95 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-3] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native96 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-7] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native98 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-9] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native97 started.2018-03-25 21:23:07.664 INFO 4668 --- [ MyExecutor-11] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native99 started.2018-03-25 21:23:07.664 INFO 4668 --- [ main] com.laojiao.securitydemo.ControllerTest : All tasks finished.2018-03-25 21:23:07.666 INFO 4668 --- [ MyExecutor-23] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native71 started.2018-03-25 21:23:07.667 INFO 4668 --- [ MyExecutor-24] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native72 started.2018-03-25 21:23:07.667 INFO 4668 --- [ MyExecutor-25] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native73 started.2018-03-25 21:23:07.669 INFO 4668 --- [ MyExecutor-26] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native74 started.2018-03-25 21:23:07.669 INFO 4668 --- [ MyExecutor-27] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native75 started.2018-03-25 21:23:07.673 INFO 4668 --- [ MyExecutor-28] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native76 started.2018-03-25 21:23:07.674 INFO 4668 --- [ MyExecutor-29] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native77 started.2018-03-25 21:23:07.674 INFO 4668 --- [ MyExecutor-30] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native78 started.2018-03-25 21:23:07.676 INFO 4668 --- [ MyExecutor-31] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native79 started.2018-03-25 21:23:07.677 INFO 4668 --- [ MyExecutor-32] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native80 started.2018-03-25 21:23:07.677 INFO 4668 --- [ MyExecutor-33] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native81 started.2018-03-25 21:23:07.677 INFO 4668 --- [ MyExecutor-34] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native82 started.2018-03-25 21:23:07.678 INFO 4668 --- [ MyExecutor-35] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native83 started.2018-03-25 21:23:07.679 INFO 4668 --- [ MyExecutor-36] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native84 started.2018-03-25 21:23:07.679 INFO 4668 --- [ MyExecutor-37] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native85 started.2018-03-25 21:23:07.679 INFO 4668 --- [ MyExecutor-38] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native86 started.2018-03-25 21:23:07.680 INFO 4668 --- [ MyExecutor-39] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native87 started.2018-03-25 21:23:07.680 INFO 4668 --- [ MyExecutor-40] c.l.securitydemo.mythreadpool.AsyncTask : Task2-Native88 started.作者:PlayInJava 链接:https://juejin.cn/post/6844903584857849870 咳嗽 https://blog.mostion.com/archives/47/ 2023-11-28T18:19:00+08:00 咳嗽是什么咳嗽是指肺失宣降,肺气上逆,发出咳声,或咳吐痰液的一种肺系病症为肺系疾病的主要症候之一就症状而论,有声无痰为咳,有痰无声为嗽。临床上往往痰声并见,难以截然分开,故以咳嗽并称。肺主呼吸肺主呼吸。是由宣发和肃降两个运动来完成的;肺气宣发,我们才能把身体的浊气排出去;肺气肃降,我们才能把吸入的清气下送至肾。肾纳气,也就是接纳清气。宣发主表,方向是向上向外;肃降主里,方向是向内向下。肺气宣发和肃降的运动协调有序,则呼吸均匀通畅。要是邪气犯肺,导致宣发和肃降功能失调,就会影响我们的气体交换,会出现胸闷,咳嗽,喘促,呼吸不利。外感咳嗽为六淫之邪,从口鼻或皮毛而入,侵袭肺系,或因吸入烟尘、异味气体,肺气被郁,肺失宣降。《河间六书》:“寒、暑、燥、湿、风、火六气,皆令人咳。张景岳:“六气皆令人咳,风寒为主。”风为六淫之首,其他外邪多随风邪侵袭人体,所以外感咳嗽常以风为先导,或夹寒,夹热,夹燥,表现为风寒、风热、风燥相合为病。内伤咳嗽由脏腑功能失调,内邪犯肺所致。或因饮食不调,嗜好烟酒,喜辛喜辣,灼伤胃阴:或因过食肥甘油腻,酿湿生痰:或因脾失健运,变生痰浊,痰邪上干;或因情志不遂,易怒伤肝,气机不畅,日久化火(肝咳,小柴胡,加味逍遥丸等,从肝治);肺部疾病,迁延不愈,肺气虚,内伤;咳嗽的病变主要是因为肺部机能失常引起的,但是与肝、脾、肾都有关系。但主要的病机就是肺气上逆。肺主气,司呼吸,上连气道、喉咙,开窍于鼻。同时肺又为娇脏,不耐寒热,易受内外之邪侵袭而致宣肃失职。外感咳嗽属于邪实,肺气上逆,雍滞不畅导致的。治疗时宜散邪宣肺。如果不及时治疗日久可能会出现转化,变为内伤咳嗽。内伤咳嗽的主要病理因素是“痰与火”。痰有寒和热的区别,而火有虚和实的不同。 Git 拉取远程分支代码并合并到本地分支 https://blog.mostion.com/archives/46/ 2023-11-16T16:20:00+08:00 1. 使用git fetch命令需要在本地额外新建分支的 :// 查看远程 git remote -v // 获取远程指定分支到本地临时新建的分支 // 获取远程master的分支的代码到临时新建的temp git fetch origin master:temp // 查看版本差异 // 查看temp分支与当前分支的差异 git diff temp // 将临时分支temp合并到当前分支 git merge tmep // 删除临时分支 git branch -D temp不要在本地新建分支的 :// 查看远程 git remote -v // 获取远程分支到本地 // 获取远程的master分支 git fetch origin master // 查看版本差异 // 查看远程master分支与本地master分支的差别 git log -p master..origin/master // 合并到本地分支 git merge origin/master2.使用git pull命令相当于git fetch与git merge一起使用,但是这样使用容易出错所以推荐第一种方式// 查看远程 git remote -v // 拉取并合并到本地分支 // 拉取远程的master分支合并到当前分支 git pull origin master 风寒感冒的症状和用药 https://blog.mostion.com/archives/44/ 2023-11-16T12:25:00+08:00 风寒感冒就是病人受风寒而发生的感冒症见:恶寒,发热,无汗,头痛, 肢体酸疼,鼻塞声重,或鼻痒喷嚏,流清涕, 咽痒,咳痰稀薄色白,口不渴或喜热饮,舌苔薄白而润,脉浮或浮紧;治法:【辛温解表】推荐中成药【风寒感冒颗粒】组方:麻黄、葛根、桂枝、防风、紫苏叶、白芷、桔梗、苦杏仁、陈皮、干姜、甘草;与 感冒清热颗粒 组方相同功效:解表发汗,疏风散寒;用于风寒感冒,发热,头痛,恶寒,无汗,咳嗽,鼻寒,流清涕;【感冒清热颗粒】组方:麻黄、葛根、桂枝、防风、紫苏叶、白芷、桔梗、苦杏仁、陈皮、干姜、甘草;与 风寒感冒颗粒 组方相同功效:解表发汗,疏风散寒;用于风寒感冒,发热,头痛,恶寒,无汗,咳嗽,鼻寒,流清涕;【正柴胡饮颗粒】组方:柴胡、陈皮、防风、甘草、赤芍、生差;功效:表散风寒,解热止痛。用于外感风寒初起:发热恶寒,无汗,头痛,鼻寒,喷嚏,咽痒咳嗽,四肢酸痛;【感冒疏风片】组方:麻黄、桂枝、苦杏仁、白芍(酒炙)、防风、紫苏叶、独活、桔梗、谷芽(炒)、生姜(捣碎)、大枣(去核)、甘草;功效:辛温解表,宜肺和电;用于风寒感冒,发热咳嗽,头痛怕冷,鼻流清涕,骨节酸痛,四肢疲倦;【荆防颗粒】组方:荆芥、防风、羌活、独活、柴胡、前胡、川弯、积亮、获芝、桔梗、甘草;功效:发汗解表,散风祛湿。用于风寒感冒,头痛身痛,恶寒无汗,鼻寒清涕,咳嗽白痰;【九味羌活丸】组方:羌活、防风、苍术、细辛、川弯、地黄、白芷、黄梦、甘章;功效:解表,散寒,除湿;用于外感风寒挟湿导致的恶寒发热无汗,头痛且重,肢体酸痛;【四季感冒片】组方:桔梗,紫苏叶,陈皮,荆芥,大青叶,连翘,甘草(炙),防风;功效:清热解表;用于四季风寒感冒引起的发热头痛,鼻流清涕,咳嗽口干,咽喉疼痛,恶心厌食;【参苏片】组方:紫苏叶,葛根,前胡,党参,茯苓,陈皮,半夏(姜制),枳壳,桔梗等13味;功效:疏风散寒,祛痰止咳;用于体弱感冒风寒,恶寒发热,头痛鼻塞,咳嗽痰多,胸闷呕逆;【午时茶】组方:苍术,柴胡,羌活,防风,白芷,川芎,广藿香,前胡,连翘,陈皮,山楂,枳实,炒麦芽,甘草,桔梗,紫苏叶,厚朴,红茶,六神曲;功效:祛风解表,化湿和中;用于外感风寒,内伤食积证,症见恶寒发热,头痛身楚,胸脘满闷,恶心呕吐,腹痛腹泻; 发热的辨证--有汗发热 https://blog.mostion.com/archives/42/ 2023-11-15T18:25:00+08:00 有什么症状?风热感冒主要症状:发热重,恶寒轻,咽干而痛,常见咽喉,扁桃体红肿疼痛,鼻塞流黄稠鼻涕,口渴想喝水,舌边尖红,苔薄黄,脉浮数;治法【辛凉解表】解表:解除表症中成药【银翘解毒片】组方:金银花,连翘,薄荷,荆芥,淡豆豉,牛蒡子(炒),桔梗,淡竹叶,甘草;功效:辛凉解表,清热解毒;用于风热感冒,症见发热头痛,咳嗽口干,咽喉疼痛;【防风通圣丸】组方:防风,荆芥,薄荷,麻黄,大黄,芒硝,栀子,滑石,桔梗,石膏,川芎,当归,白芍,黄芩,连翘,甘草,白术;功效:解表通里,清热解毒;用于风热壅盛,表里俱实证。症见憎寒壮热,头目昏眩,目赤睛红,口苦而干,咽喉不利,溲赤便干等。脉象:脉数有力(轻重按都有力)【双黄连口服液、复方金银花颗粒】组方:金银花,黄芩,连翘功效:疏风解表,清热解毒;用于外感风热所致的感冒,症见发热、咳嗽、咽痛;【羚翘解毒片(颗粒)】组方:羚羊角,金银花,连翘,薄荷,荆芥穗,淡豆豉,牛蒡子(炒),桔梗,赤芍,淡竹叶,甘草;功效:疏风清热,解毒;用于风热感冒,恶寒发热,头晕目眩,咳嗽,咽痛;【清开灵颗粒】组方:胆酸,珍珠母,猪去氧胆酸,栀子,水牛角,板蓝根,黄芩苷,金银花;功效:清热解毒,镇静安神;用于外感风热所致发热,烦躁不安,咽喉肿痛; 发热的辨证--无汗畏寒 https://blog.mostion.com/archives/41/ 2023-11-15T11:27:00+08:00 什么是无汗发热?主要症状:恶寒,发热,头痛,关节疼痛明显,鼻塞声重,流清鼻涕,口不渴,咳嗽时吐稀痰,咽喉疼痛不明显,舌不红,苔薄白,脉浮紧(轻搭有,像紧紧的绳子,代表病邪在表);治疗方法【解表散寒】推荐中成药【葛根汤颗粒】组方:葛根,麻黄,白芍,桂枝,甘草,大枣,生姜功效:发汗解表,生津舒筋;用于风寒感冒,证见:发热恶寒,鼻塞流涕,咽嗽咽痒,咯痰稀白,无汗,头痛身疼,项背强急不舒,苔薄白或薄白润,脉浮或脉紧;【风寒感冒颗粒】组方:麻黄,葛根,紫苏叶,防风,桂枝,白芷,陈皮,苦杏仁,桔梗,甘草,干姜功效:解表发汗,疏风散寒;用于感冒身热,头痛,咳嗽,鼻塞,流涕;【正柴胡饮颗粒】组方:柴胡,陈皮,防风,甘草,赤芍,生姜功效:表散风寒,解热止痛;用于外感风寒初起;发热恶寒,无汗,头痛,鼻塞,喷嚏,咽痒咳嗽,四肢酸痛;【午时茶】组方:苍术,柴胡,羌活,防风,白芷,川芎,广藿香,前胡,连翘,陈皮,山楂,枳实,炒麦芽,甘草,桔梗,紫苏叶,厚朴,红茶,六神曲功效:祛风解表,化湿和中;用于外感风寒,内伤食积证,症见恶寒发热,头痛身楚,胸脘满闷,恶心呕吐,腹痛腹泻; 发热的辨证--虚火 https://blog.mostion.com/archives/40/ 2023-11-15T11:08:08+08:00 什么叫温病虚症(虚火)?无明显外感表证,症见初起头痛身痛,先恶寒(或不寒)后发热,发热之后但热不寒,咽喉肿痛,口干,神智昏迷,精神倦怠,不思饮食,小便短小、黄,舌质红,苔少或无苔,脉虚洪;温病误用石膏,必死(生石膏用于实证发热,凉药)治法【收敛浮火,酸甘化阴】中成药推荐【乌梅白糖汤】组方:乌梅7颗,白糖50g,煮水温服;功效:酸甘化阴,收敛浮火;乌梅酸收,舒肝气降胆气,敛浮火,补木气,为治疗肝胆虚证的要药;白糖补中气而不横滞,与乌梅酸甘生阴,最宜温病虚证;【乌梅三豆饮】组方:乌梅七颗,黄豆,黑豆,绿豆各一把;功效:黄豆,黑豆,养肝木补中气平疏泄,兼能降胆气伏相火生津液。绿豆养木养中,兼清肺热;两方区别在于脉象:乌梅汤 -- 脉洪虚,轻按有力,重按无;三豆饮 -- 脉虚小,轻按微弱,重按无;服用要点:需要煮1.5-2小时,豆烂汁浓。当日煮当日服,绝不能过夜; 发热的辨证--往来寒热 https://blog.mostion.com/archives/39/ 2023-11-15T10:09:00+08:00 什么叫往来寒热?恶寒与发热交替出现,一日数次发作,同事兼见胸胁苦满,食欲不振,心烦喜呕,口苦咽干,舌苔薄白或黄,脉弦;(感觉身体忽冷忽热,一会儿出点儿汗,一会儿就特别冷;)治疗方法【和解少阳】本症型多由邪在少阳,经气不利,郁而化热所致;少阳病症,邪不在表,也不再里,汗,吐,下三法均不适宜,只有采用和解方法;中成药推荐【小柴胡颗粒】组方:柴胡、黄芩、半夏(姜制)、党参、生姜、甘草、大枣(党参、生姜、甘草、大枣 这四味药叫做脾四味,补中益气,扶正祛邪,帮助脾胃化生出气血津液;)功效: 解表散热,舒肝和胃;用于往来寒热,胸胁苦满,默默不欲饮食,心烦喜呕,口苦咽干;成人可以喝四包,儿童可以吃两包 子午流注图 https://blog.mostion.com/archives/38/ 2023-11-10T13:08:00+08:00 肺寅大卯胃辰宫,脾巳心午小未中,申膀酉肾心包戌,亥焦子胆丑肝通。1、肺寅,即寅时(凌晨3点-5点)对应的是肺经,此时肺经当令,是人体阳气的初始,也是人体气血由静变动的开始。此时不要急于起床,这样有助于阳气的生长,为白天的劳作打好基础。2、大卯,即卯时(凌晨5点-7点)对应的是大肠经,此时大肠经当令,曙光初放,是起床的最好时机。先伸展肢体,接着慢慢坐起,坐在床上一会儿,并做一些养生保健的小动作,如叩齿、搓面、转肩、指弹后脑等等。然后起床洗漱,洗漱后马上喝一杯温开水,以助排便。3、胃辰,即辰时(上午7点-9点)对应的是胃经,此时胃经当令,胃液分泌旺盛,是享受早餐的最佳时机。早餐应注重营养搭配,提倡清淡、稍饱。4、脾巳,即巳时(上午9点-11点)对应的是脾经,此时脾经当令,阳气最盛,可以做适量的体能锻炼,做到锻炼有道,锻炼有度。5、心午,即午时(上午11点-午后1点)对应的是心经,此时心经当令。午餐时间,讲究荤素搭配,营养丰富。可先喝点汤,然后再吃饭菜,七八分饱即可。饭后漱漱口,可以午睡一小时左右。6、小未,即未时(午后1-3点)对应的是小肠经,此时小肠经当令,可看书、学习、下棋、打牌、做家务。喝一杯茶,以帮助肠道吸收。7、申膀,即申时(午后3-5点)对应的是膀胱经,此时膀胱经当令,应注意多喝水,让小便通畅,切忌憋尿。此时是学习和做兴趣事的最佳时间。8、酉肾,即酉时(午后5-7点)对应的是肾经,此时肾经当令,气血走足少阴肾经,为肾虚者补肾的最好时机。晚饭宜粥、少量、清谈。晚饭后少休息片刻,然后洗漱一下。9、心包戌,即戌时(晚上7-9点)对应的是心包经,此时心包经当令,可上上网、看看电视。睡前用热水泡脚,不少于20分钟。10、亥焦,即亥时(晚上9-11点)对应的是三焦经,此时三焦经当令,气血灌注三焦经。提倡排除杂念,静心安神,以养元气。屈膝而卧,渐渐入梦。11、子胆,即子时(晚上11点-凌晨1点)对应的是胆经,此时胆经当令,必须熟睡,不可熬夜。人的阳气是在优质睡眠中得以蓄积。12、丑肝,即丑时(凌晨1点-3点)对应的是肝经,此时肝经当令,肝脏在解毒造血。 良好的睡眠状态是最好的养肝、保肝之法。