Tag Archives: Java basics

[Solved] JDK Install Error /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory

CentOS 7.6 JDK installation, download the following JDK package

wget https://mirrors.huaweicloud.com/java/jdk/8u201-b09/jdk-8u201-linux-i586.tar.gz

After installation. After configuring environment variables, execute Java – version to report an error

-bash: /root/jdk1.8.0_201/bin/java: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory


Solution
Just run sudo yum install glibc.i686
Then look at java -version OK!

Shell Script syntax error near unexpected token `done’

1. Modify the file type
Vi finddir.sh enter: set ff If fileformat= DOS, change to Unix: : set FF = Unix execute save command: : WQ
2. Delete hidden characters
Open your SHELL script file with the command VI-b, and you will. It is found that there is an extra ^M at the end of each line of the script because MS-DOS and Windows are return + line feed to represent line feed. Therefore, Vim is used in Linux to view the code written in Windows with VC. The “^M” symbol at the end of the line represents the character.
To eliminate “^M” in Vim with the substitution function, type the following substitution command line: 1) vi-b setup.sh2) on the command edit line
< That is: press ESC and shift: colon >
Note: the “M” character on the command line above is not “” and” M “, but is generated by “Ctrl V” and “Ctrl M”. After this substitution, the save is ready to be executed.

Hystrix fuse of spring cloud system

Problem phenomenon: continuous clicking causes the fusing of hystrix

The solution on the Internet is to adjust the maxqueuesize property. After the modification, the following error still appears. Why does the maxqueuesize property not work?Later, by checking the official documents, we found that hystrix also has a queuesizerejectionthreshold property, which controls the maximum threshold of the queue. By default, hystrix only has five, Therefore, even if we set the maxqueuesize value to be larger, it will not work. Both properties must be configured at the same time

could not be queued for execution and no fallback available

Solution

hystrix:
  threadpool:
    default:
      coreSize: 200 #Maximum number of threads for concurrent execution, default 10
      maxQueueSize: 1000 #Max queue size of BlockingQueue, default -1
      queueSizeRejectionThreshold: 800 #Even if maxQueueSize is not reached, the request will be rejected after reaching the value of queueSizeRejectionThreshold

Java operation temporary file creation and deletion

in Java’s File class, there is a createTempFile(String prefix,String suffix) that is called to create a temporary File in the system’s default temporary File directory.
prefix means filename.
suffix represents the suffix of a file, in the form “. TMP “, note that “. “

is needed

final File htmlFile = File.createTempFile("temp", ".html");//创建临时文件
logger.info("临时文件所在的本地路径:" + htmlFile.getCanonicalPath());
FileOutputStream fos = new FileOutputStream(htmlFile);
try {
   //这里处理业务逻辑
} finally {
    //关闭临时文件
    fos.flush();
    fos.close();

    htmlFile.deleteOnExit();//程序退出时删除临时文件
}

on win7, the default directory for temporary files is C:\Users\Administrator\AppData\Local\Temp. After
finishes using the temporary file, executing htmlfile.deleteonexit () will automatically delete the temporary file.

Java foundation — printing Yang Hui triangle

problem: print out a 10-line yanghui triangle
point: two-dimensional array
idea: first analyze the law of yanghui triangle: 1. 2. Each line ends with a 1; 3. Starting from the third row, every non-first and last number is: yangHui[I][j]=yangHui[i-1][j-1]+yangHui[i-1][j]. The code is:

//        1.声明初始化二维数组
        int[][] yangHui = new int[10][];
//        2.给数组的元素赋值
        for (int i = 0; i < yangHui.length; i++) {
            yangHui[i] = new int[i+1];
//            2.1 给首末元素赋值
            yangHui[i][0] = 1;
            yangHui[i][i] = 1;
//            2.2 给每行的非首末元素赋值
            if (i>1){
                for (int j = 1; j <yangHui[i].length-1 ; j++) {
                    yangHui[i][j]=yangHui[i-1][j-1]+yangHui[i-1][j];
                }
            }
        }
        
//        3.遍历二维数组
        for (int i = 0; i < yangHui.length; i++) {
            for (int j = 0; j <yangHui[i].length ; j++) {
                System.out.print(yangHui[i][j]+"\t");
            }
            System.out.println();
        }

Output:

1 1 1 2 1 1 3 3 1

1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28日8 1
1 9 36 84 126 126 84 36 9 1

MongoDB Error: Query failed with error code 2 and error message ‘Field ‘locale’ is invalid

is a very bad exception:

2020-06-29 18:44:40.940 ERROR 15164 --- [nio-9002-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017] with root cause

com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "user" }' on server 192.168.10.105:27017
	at com.mongodb.internal.operation.FindOperation$1.call(FindOperation.java:635) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation$1.call(FindOperation.java:625) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.OperationHelper.withReadConnectionSource(OperationHelper.java:462) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:625) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.internal.operation.FindOperation.execute(FindOperation.java:77) ~[mongodb-driver-core-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:190) ~[mongodb-driver-sync-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.execute(MongoIterableImpl.java:135) ~[mongodb-driver-sync-4.0.4.jar:na]
	at com.mongodb.client.internal.MongoIterableImpl.iterator(MongoIterableImpl.java:92) ~[mongodb-driver-sync-4.0.4.jar:na]
	at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2771) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1757) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1752) ~[spring-data-mongodb-3.0.1.RELEASE.jar:3.0.1.RELEASE]
	at com.coldlight.mongo.service.impl.UserServiceImpl.getAllUser(UserServiceImpl.java:36) ~[classes/:na]
	at com.coldlight.mongo.controller.UserController.getAllUser(UserController.java:28) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_251]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_251]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_251]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:879) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:793) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:660) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.7.RELEASE.jar:5.2.7.RELEASE]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:373) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_251]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_251]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.36.jar:9.0.36]
	at java.lang.Thread.run(Thread.java:748) [na:1.8.0_251]

I did not change anything, just added a comment, suddenly error, why and the network said different, then take a closer look at the blog, my own problem, here first explain the problem

I misannotated

//正确的
@Document(collection  = "user")

is written as

//导致错误的
@Document(collation  = "user")

collection and collation are not the same.