# fileSystem **Repository Path**: wangman1991/fileSystem ## Basic Information - **Project Name**: fileSystem - **Description**: 学习资料 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2017-02-27 - **Last Updated**: 2025-02-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #fileSystem ###查找文件中是否存在某字符串、插入字符串 ``` # restart when startup if [ `grep -c "/opt/athena/restart.sh" /etc/rc.local` -eq '0' ]; then sed -i '$i\/opt/athena/restart.sh' /etc/rc.local fi ``` ###模糊匹配,删除文件中包含该字符串的行 ``` sed -i '/athena/d' /etc/rc.local ``` 对于ThreadLocal的使用,Spring的源码中有大量的应用,主要是要支持Singleton的实例管理,那么自身的一些Singleton的实现内非线程安全的变量,属性要用ThreadLocal隔离共享。再看ThreadLocal和synchronized的本质。前者不在乎多占点空间,但是绝对的忍受不了等待;后者对等待无所谓,但是就是不喜欢浪费空间。这也反映出了算法的一个规律:通常是使用场景决定时间和空间的比例,既省时又省地的算法多数情况下只存在于幻想之中。 Redis作为消息中间件的配置: ``` @Configuration public class RedisSubListenerConfig { //初始化监听器 @Bean RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory, MessageListenerAdapter listenerAdapter) { RedisMessageListenerContainer container = new RedisMessageListenerContainer(); container.setConnectionFactory(connectionFactory); container.addMessageListener(listenerAdapter, new PatternTopic("seckill")); return container; } //利用反射来创建监听到消息之后的执行方法 @Bean MessageListenerAdapter listenerAdapter(RedisConsumer redisReceiver) { return new MessageListenerAdapter(redisReceiver, "receiveMessage"); } //使用默认的工厂初始化redis操作模板 @Bean StringRedisTemplate template(RedisConnectionFactory connectionFactory) { return new StringRedisTemplate(connectionFactory); } } ``` 使用: 发消息: ``` public void sendChannelMess(String channel, String message) { stringRedisTemplate.convertAndSend(channel, message); } ``` 接收消息: ``` @Service public class RedisConsumer { @Autowired private ISeckillService seckillService; @Autowired private RedisUtil redisUtil; public void receiveMessage(String message) { //收到通道的消息之后执行秒杀操作(超卖) } } ```