current position:Home>Springboot2, linux environment advanced programming pdf
Springboot2, linux environment advanced programming pdf
2022-01-27 01:40:50 【m0_ sixty-four million eight hundred and sixty-seven thousand e】
database: 0
dnsMonitoringInterval: 5000 #DNS Monitoring intervals ( millisecond ), Default 5000
threads: 16
nettyThreads: 32
codec: !<org.redisson.codec.JsonJacksonCodec> {}
#“transportMode”: “NIO”
Cluster pattern :
clusterServersConfig:
idleConnectionTimeout: 10000
pingTimeout: 1000
connectTimeout: 10000
timeout: 3000
retryAttempts: 3
retryInterval: 1500
reconnectionTimeout: 3000
failedAttempts: 3
password: null
subscriptionsPerConnection: 5
clientName: null
loadBalancer: !<org.redisson.connection.balancer.RoundRobinLoadBalancer> {}
slaveSubscriptionConnectionMinimumIdleSize: 1
slaveSubscriptionConnectionPoolSize: 50
slaveConnectionMinimumIdleSize: 32
slaveConnectionPoolSize: 64
masterConnectionMinimumIdleSize: 32
masterConnectionPoolSize: 64
readMode: “SLAVE”
nodeAddresses:
-
“redis://127.0.0.1:7004”
-
“redis://127.0.0.1:7001”
-
“redis://127.0.0.1:7000”
scanInterval: 1000
threads: 0
nettyThreads: 0
codec: !<org.redisson.codec.JsonJacksonCodec> {}
#“transportMode”:“NIO”
Injection profile
Here, the configuration file is read according to the environment
RedissionConfig
package com.dzhjj.dzhjjapi.config;
《 A big factory Java Analysis of interview questions + Back end development learning notes + The latest architecture explanation video + Practical project source code handout 》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 Full content open source sharing
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.SingleServerConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.redisson.config.Config;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;
import java.io.IOException;
/**
-
@Auther: heng
-
@Date: 2020/12/3 13:56
-
@Description: redission Distributed lock
-
@Version 1.0.0
*/
@Order(2)
@Slf4j
@Configuration
public class RedissionConfig {
//@Autowired
// private RedisProperties redisProperties;
@Autowired
private Environment env;
/**
-
standalone mode
-
@return
//
@Bean
public RedissonClient redissonClient() {
RedissonClient redissonClient;
Config config = new Config();
String url = “redis://” + redisProperties.getHost() + “:” + redisProperties.getPort();
SingleServerConfig serverConfig = config.useSingleServer()
.setAddress(url)
.setTimeout(3000)
.setDatabase(redisProperties.getDatabase())
.setConnectionPoolSize(64)
.setConnectionMinimumIdleSize(50);
if (StringUtils.isNotBlank(redisProperties.getPassword())) {
serverConfig.setPassword(redisProperties.getPassword());
}
try {
redissonClient = Redisson.create(config);
return redissonClient;
} catch (Exception e) {
log.error(“RedissonClient init redis url:[{}], Exception:”, url, e);
return null;
}
}*/
@Bean(destroyMethod = “shutdown”)
public RedissonClient redisson() throws IOException {
Config config = Config.fromYAML(new ClassPathResource(“application-single-”+env.getActiveProfiles()[0]+".yml").getInputStream());
RedissonClient redisson = Redisson.create(config);
return redisson;
}
}
Test the distributed lock code
@Autowired
private RedissonClient redissonClient;
public Object testRedisLoak(){
Boolean result=false;
final String lockKey= “RedissonLock”;
RLock lock=redissonClient.getLock(lockKey);
try {
//TODO: The first parameter 30s= Indicates an attempt to acquire a distributed lock , And the maximum waiting time for obtaining the lock is 30s
//TODO: The second parameter 10s= Indicates that after locking ,10s The lock will be released automatically after the internal operation
Boolean cacheRes=lock.tryLock(10,10, TimeUnit.SECONDS);
return cacheRes;
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
//TODO: Release the lock
lock.unlock();
}
return result;
}
Start integrating annotation mode
Definition notes : RsionLock
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.*;
/**
-
Description:
-
-
Annotations for distributed locks
-
Use in pairs in the same annotation , For example, in the sample code ,value and path They are aliases for each other .
-
But be careful ,@AliasFor There are some restrictions on the use of labels , But this should come to mind , For example, attribute value types that require mutual aliases , The default value is , It's all the same , Mutually alias annotations must appear in pairs , such as value Attribute added @AliasFor(“path”),
-
that path Property must be added @AliasFor(“value”), One other thing , Properties that are aliases to each other must have default values defined .
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface RsionLock {
/**
-
Support spring El expression
-
Locked resources ,key.
*/
//@AliasFor(“value”)
String key() default “”;
/**
-
Support spring El expression
-
Locked resources ,value.
-
If it is not empty, this time splicing key
*/
//@AliasFor(“key”)
String value() default “”;
/**
-
Holding time , Company : second
-
TODO:10s= Indicates that after locking ,10s The lock will be released automatically after the internal operation
*/
long lockTime() default 10;
/**
- When the acquisition fails, the action
*/
// LockFailAction action() default LockFailAction.CONTINUE;
/*public enum LockFailAction{
//* give up //
GIVEUP,
//* continue //
CONTINUE;
}*/
/**
-
Waiting time , Company : second
-
TODO:10s= Indicates an attempt to acquire a distributed lock , And the maximum waiting time for obtaining the lock is 10s
-
@return
*/
int waitTime() default 10;
/**
-
Whether the automatic extension mechanism
-
Automatic extension is not allowed by default
-
@return
*/
boolean isWatchDog() default false;
/**
-
Extension of time Company : second
-
@return
*/
int watchDogTime() default 2;
}
Define the annotation facet LockAspectConfiguration
import com.dzhjj.dzhjjapi.annotations.RsionLock;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;
/**
-
@Auther: heng
-
@Date: 2020/12/3 17:50
-
@Description: LockAspectConfiguration
-
@Version 1.0.0
*/
@Slf4j
@Aspect
@Configuration
public class LockAspectConfiguration {
private ExpressionParser parser = new SpelExpressionParser();
private LocalVariableTableParameterNameDiscoverer discoverer = new LocalVariableTableParameterNameDiscoverer();
@Autowired
private RedissonClient redissonClient;
/**
- Defining entry points
*/
@Pointcut("@annotation(com.dzhjj.dzhjjapi.annotations.RsionLock)")
private void lockPoint() {
}
/**
-
Surrounding the notification
-
@param pjp pjp
-
@return Method returns the result
-
@throws Throwable throwable
*/
@Around(“lockPoint()”)
public Object around(ProceedingJoinPoint pjp) throws Throwable {
Method method = ((MethodSignature) pjp.getSignature()).getMethod();
RsionLock lockAction = method.getAnnotation(RsionLock.class);
String logKey = getLogKey(lockAction, pjp, method);
copyright notice
author[m0_ sixty-four million eight hundred and sixty-seven thousand e],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270140473677.html
The sidebar is recommended
- Spring IOC container loading process
- [thinking] the difference between singleton mode and static method - object-oriented programming
- Hadoop environment setup (MySQL environment configuration)
- 10 minutes, using node JS creates a real-time early warning system for bad weather!
- Git tool
- Force deduction algorithm - 92 Reverse linked list II
- What is the sub problem of dynamic programming?
- C / C + +: static keyword summary
- Idea does not have the artifacts option when configuring Tomcat
- Anaconda can't open it
guess what you like
-
I don't know how to start this
-
Matlab simulation of transportation optimization algorithm based on PSO
-
MySQL slow log optimization
-
[Vue] as the window is stretched (larger, smaller, wider and higher), the text will not be displayed
-
Popular Linux distributions for embedded computing
-
Suzhou computer research
-
After installing SSL Certificate in Windows + tomcat, the domain name request is not successful. Please answer!!
-
Implementation time output and greetings of jQuery instance
-
The 72 year old uncle became popular. Wu Jing and Guo fan made his story into a film, which made countless dreamers blush
-
How to save computer research
Random recommended
- Springboot implements excel import and export, which is easy to use, and poi can be thrown away
- The final examination subjects of a class are mathematical programming, and the scores are sorted and output from high to low
- Two pronged approach, Tsinghua Professor Pro code JDK and hotspot source code notes, one-time learning to understand
- C + + recursive knapsack problem
- The use of GIT and GitHub and the latest git tutorial are easy to understand -- Video notes of crazy God speaking
- PostgreSQL statement query
- Ignition database test
- Context didn't understand why he got a high salary?, Nginxfair principle
- Bootstrap switch switch control user's guide, springcloud actual combat video
- A list that contains only strings. What other search methods can be used except sequential search
- [matlab path planning] multi ant colony algorithm grid map path planning [including GUI source code 650]
- [matlab path planning] improved genetic algorithm grid map path planning [including source code phase 525]
- Iinternet network path management system
- Appium settings app is not running after 5000ms
- Reactnative foundation - 07 (background image, status bar, statusbar)
- Reactnative foundation - 04 (custom rpx)
- If you want an embedded database (H2, hsql or Derby), please put it on the classpath
- When using stm32g070 Hal library, if you want to write to flash, you must perform an erase. If you don't let it, you can't write continuously.
- Linux checks where the software is installed and what files are installed
- SQL statement fuzzy query and time interval filtering
- 69. Sqrt (x) (c + + problem solving version with vs runnable source program)
- Fresh students are about to graduate. Do you choose Java development or big data?
- Java project: OA management system (java + SSM + bootstrap + MySQL + JSP)
- Titanic passenger survival prediction
- Vectorization of deep learning formula
- Configuration and use of private image warehouse of microservice architect docker
- Relearn JavaScript events
- For someone, delete return 1 and return 0
- How does Java dynamically obtain what type of data is passed? It is used to judge whether the data is the same, dynamic data type
- How does the database cow optimize SQL?
- [data structure] chain structure of binary tree (pre order traversal) (middle order traversal) (post order traversal) (sequence traversal)
- Webpack packaging optimization solution
- 5. Operation element
- Detailed explanation of red and black trees
- redhat7. 9 install database 19C
- Blue Bridge Cup notes: (the given elements are not repeated) complete arrangement (arrangement cannot be repeated, arrangement can be repeated)
- Detailed explanation of springboot default package scanning mechanism and @ componentscan specified scanning path
- How to solve the run-time exception of test times
- Detailed explanation of k8s management tool kubectl
- Android system view memory command