Giter VIP home page Giter VIP logo

interview-learn's People

Contributors

xie-chong avatar

Watchers

 avatar

interview-learn's Issues

SpringCloud:SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

在使用springcloud的过程中,启动时出现SpringApplicationBuilder.([Ljava/lang/Object;)V这个错误,找了半天,发觉是版本问题,一开始我是使用的是springboot1.5x的版本,官方文档指出springboot1.5x版本,springcloud要使用Edgware.SR3这个版本号,如果springboot版本为2.x的话,springcloud要使用Finchley.SR1。

即将<spring-cloud.version>Edgware.SR3</spring-cloud.version>改为<spring-cloud.version>Finchley.SR1</spring-cloud.version>

正确的姿势

   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.4.RELEASE</version>
    </parent>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Dalston.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

RabbitMQ: plugins_not_found, [:"rabbitmq-management"]

报错:

[root@xiecentos plugins]# rabbitmq-plugins enable rabbitmq-management
Enabling plugins on node rabbit@xiecentos:
rabbitmq-management
Error:
{:plugins_not_found, [:"rabbitmq-management"]}
[root@xiecentos plugins]#

解决方案:需要在代理服务器的sbin文件夹下运行一下命令

[root@xiecentos sbin]# ./rabbitmq-plugins enable rabbitmq_management
Enabling plugins on node rabbit@xiecentos:
rabbitmq_management
The following plugins have been configured:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch
Applying plugin configuration to rabbit@xiecentos...
The following plugins have been enabled:
  rabbitmq_management
  rabbitmq_management_agent
  rabbitmq_web_dispatch

set 3 plugins.
Offline change; changes will take effect at broker restart.
[root@xiecentos sbin]# pwd
/usr/lib/rabbitmq/lib/rabbitmq_server-3.8.3/sbin
[root@xiecentos sbin]# 

RabbitMQ: missing_sample_retention_policies

报错:

Application rabbitmq_management_agent exited with reason: {{shutdown,{failed_to_start_child,rabbit_mgmt_agent_sup,{shutdown,{failed_to
_start_child,channel_queue_exchange_metrics_metrics_collector,{bad_return_value,missing_sample_retention_policies}}}}},{rabbit_mgmt_agent_app,start,[normal,[]]}}
Application rabbitmq_management_agent exited with reason: {{shutdown,{failed_to_start_child,rabbit_mgmt_agent_sup,{shutdown,{failed_to
_start_child,channel_queue_exchange_metrics_metrics_collector,{bad_return_value,missing_sample_retention_policies}}}}},{rabbit_mgmt_agent_app,start,[normal,[]]}}

配置文件忘记取消注释

# management.sample_retention_policies.detailed.10 = 5

RabbitMQ: 远程登陆遇到问题 User can only log in via localhost

RabbitMQ-login

原因:rabbitmq从3.3.0开始禁止使用guest/guest权限通过除localhost外的访问

将:{loopback_users, [<<”guest”>>]},改为:{loopback_users, []},
或者新建一个用户,并且赋予超级管理员(administrator)权限

官方文档:
仅允许通过环回接口(即“ localhost”)连接到代理的用户列表。
要允许默认的“ guest”用户远程连接(一种不适合生产使用的安全做法),请将其设置为“ none”:

loopback_users = none

此外,还需要关注防火墙是否开启

firewall-cmd --zone=public --add-port=5672/tcp --permanent

firewall-cmd --zone=public --add-port=15672/tcp --permanent

firewall-cmd --reload

MySQL-error: Establishing SSL connection without server’s identity verification is not recommended.

WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

解决方案:

# spring.datasource.url=jdbc:mysql://127.0.0.1:3306/stock?Unicode=true&characterEncoding=UTF-8
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/stock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false&serverTimezone=UTC

完整配置:

### xxl-job, datasource
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/stock?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true&useSSL=false&serverTimezone=UTC

spring.datasource.username=root
spring.datasource.password=mysql
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.tomcat.max-wait=10000
spring.datasource.tomcat.max-active=30
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.validation-query=SELECT 1
spring.datasource.tomcat.validation-interval=30000

elasticsearch:Exception in thread "main" java.nio.file.AccessDeniedException:

[xiecentos@xiecentos bin]$ ./elasticsearch
Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch-7.6.2/config/jvm.options
at java.base/sun.nio.fs.UnixException.translateToIOException(UnixException.java:90)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:111)
at java.base/sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:116)
at java.base/sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:219)
at java.base/java.nio.file.Files.newByteChannel(Files.java:374)
at java.base/java.nio.file.Files.newByteChannel(Files.java:425)
at java.base/java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:420)
at java.base/java.nio.file.Files.newInputStream(Files.java:159)
at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:64)

错误原因:使用非 root用户启动ES,而该用户的文件权限不足而被拒绝执行。

解决方法: chown -R 用户名:用户名 文件(目录)名

RabbitMQ:Socket Closed

客户端启动时尝试建立RabbitMQ连接,总是提示如下信息,需要多次重新启动客户端。

2020-05-05 22:29:28.290 INFO [user-center,,,] 23912 --- [3)-192.168.35.1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [local.rabbitmq.com:5672]
2020-05-05 22:29:33.323 ERROR [user-center,,,] 23912 --- [168.35.149:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured

java.net.SocketException: Socket Closed
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_231]
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_231]
at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_231]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_231]
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246) ~[na:1.8.0_231]
at java.io.BufferedInputStream.read(BufferedInputStream.java:265) ~[na:1.8.0_231]
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288) ~[na:1.8.0_231]
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:91) ~[amqp-client-5.1.2.jar:5.1.2]
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:164) ~[amqp-client-5.1.2.jar:5.1.2]
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:580) ~[amqp-client-5.1.2.jar:5.1.2]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_231]

2020-05-05 22:29:33.323 WARN [user-center,,,] 23912 --- [3)-192.168.35.1] o.s.b.a.amqp.RabbitHealthIndicator : Rabbit health check failed

elasticsearch:"can not run elasticsearch as root"

[root@xiecentos bin]# ./elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2020-05-12T17:21:04,235][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:174) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125) ~[elasticsearch-cli-7.6.2.jar:7.6.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.6.2.jar:7.6.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.6.2.jar:7.6.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170) ~[elasticsearch-7.6.2.jar:7.6.2]
... 6 more
uncaught exception in thread [main]
java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349)
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:170)
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:161)
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:125)
at org.elasticsearch.cli.Command.main(Command.java:90)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:126)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92)
For complete error details, refer to the log at /usr/local/elasticsearch-7.6.2/logs/my-application.log

问题原因:这是不能使用root用户操作,使用其他的用户再试试

Java: Arrays.sort();方法的参数类型不正确导致数组排序错误

static void | sort(byte[] a)按照数字顺序排列指定的数组。
static void | sort(byte[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(char[] a)按照数字顺序排列指定的数组。
static void | sort(char[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(double[] a)按照数字顺序排列指定的数组。
static void | sort(double[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(float[] a)按照数字顺序排列指定的数组。
static void | sort(float[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(int[] a)按照数字顺序排列指定的数组。
static void | sort(int[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(long[] a)按照数字顺序排列指定的数组。
static void | sort(long[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static void | sort(Object[] a)对指定对象升序排列的阵列,根据natural ordering的元素。
static void | sort(Object[] a, int fromIndex, int toIndex)对指定对象升序排列的数组的指定范围内,根据natural ordering的元素。
static void | sort(short[] a)按照数字顺序排列指定的数组。
static void | sort(short[] a, int fromIndex, int toIndex)按升序排列数组的指定范围。
static <T> void | sort(T[] a, Comparator<? super T> c)根据指定的比较器引发的顺序对指定的对象数组进行排序。
static <T> void | sort(T[] a, int fromIndex, int toIndex, Comparator<? super T> c)根据指定的比较器引发的顺序对指定的对象数组的指定范围进行排序。

API

Java: Stack的使用总结clone(),clear(),涉及到引用的变化

  • 方案1(Excel效果达到,但BuyAndSaleNumbers内的信息不独立)
  • 方案2(Excel效果没达到,但BuyAndSaleNumbers内的信息独立)
  • 方案3(Excel效果达到,BuyAndSaleNumbers内的信息独立)

StockPriceCompute.java

   public void compute() throws IOException {
        List<StockEntity> stocks = stockDao.findAll();

        List<Stack<Double>> listStockPrice = new ArrayList<>();
        List<String> listStockName = new ArrayList<>();

        Queue<String> stockNameQueue = new LinkedList<String>();

        stockTypeNum = stocks.size();

        for (StockEntity stock : stocks) {
            listStockName.add(stock.getName());

            //添加元素,add()和remove()方法在失败的时候会抛出异常(不推荐)
            stockNameQueue.offer(stock.getName());

            Stack<Double> upPriceStack = new Stack<>();//上涨价集合
            Stack<Double> downPriceStack = new Stack<>();//下跌价集合
            Stack<Double> buyAndSaleNumbers;//

            initBaseData(stock);

//            upPriceStack.clear();
//            downPriceStack.clear();
//            BuyAndSaleNumbers.clear();

            upPriceStack.push(openingPrice);
            upPriceStack.push(limitUpPrice);
            downPriceStack.push(openingPrice);
            downPriceStack.push(limitDownPrice);

            int m = count, n = count;
            while (m > 0) {
                double tempUpBase = upPriceStack.peek();
                upPriceStack.push((1 - goldenRato) * openingPrice + goldenRato * tempUpBase);
                m--;
            }

            while (n > 0) {
                double tempDownBase = downPriceStack.peek();
                downPriceStack.push((1 - goldenRato) * openingPrice + goldenRato * tempDownBase);
                n--;
            }

            buyAndSaleNumbers = StockBuyAndSaleNumbersCompute.computeAvailableNumbers(availableNumbers, count);

            listStockPrice.add(upPriceStack);
            listStockPrice.add(downPriceStack);
            
            // 方案1(Excel效果达到,但BuyAndSaleNumbers内的信息不独立)
            /*
            listStockPrice.add(buyAndSaleNumbers);
            printStockComputeResults(stock, upPriceStack, downPriceStack, buyAndSaleNumbers);
            */

            // 方案2(Excel效果没达到,但BuyAndSaleNumbers内的信息独立)
            /*
            listStockPrice.add(buyAndSaleNumbers);
            printStockComputeResults(stock, upPriceStack, downPriceStack, buyAndSaleNumbers);
            buyAndSaleNumbers.clear();
            */

            // 方案3(Excel效果达到,BuyAndSaleNumbers内的信息独立)
            listStockPrice.add((Stack<Double>) buyAndSaleNumbers.clone());
            printStockComputeResults(stock, upPriceStack, downPriceStack, buyAndSaleNumbers);
            buyAndSaleNumbers.clear();
        }
        GenericStockExcel.genericExcelForStockTransaction(listStockPrice, stockNameQueue, stockTypeNum, count);
    }

StockBuyAndSaleNumbersCompute.java

public class StockBuyAndSaleNumbersCompute {

    private static double availableNumbers = 0;
    private static Stack<Double> numbers = new Stack<>();// 买卖黄金率计算数
    private static double goldenRato = 0.618;// 黄金比率


    public static Stack<Double> computeAvailableNumbers(double availableNumbers, int count) {
        int computCount = count;
        availableNumbers = availableNumbers;

        numbers.push(availableNumbers);
        while (computCount > 0) {

            double temp = numbers.peek();
            double tempResult = temp * goldenRato;
            numbers.push(tempResult);
            computCount--;
        }
        return numbers;
    }
}

方案1输出结果:

 - ###科大讯飞###
 - -----------upPriceStack--------------:[41.88, 47.08, 45.0936, 43.8660048, 43.1073509664, 42.6385028972352, 42.348754790491355]
- -----------downPriceStack--------------:[41.88, 38.52, 39.80352, 40.59673536, 41.086942452479995, 41.38989043563264, 41.57711228922097]
- -----------BuyAndSaleNumbers--------------:[9.0, 5.562, 3.437316, 2.124261288, 1.312793475984, 0.8113063681581121]
----------
 - ###**平安###
- -----------upPriceStack--------------:[81.57, 90.7, 87.21234, 85.05696612, 83.72494506216, 82.90175604841488, 82.3930252379204]
 - -----------downPriceStack--------------:[81.57, 74.21, 77.02152, 78.75903936, 79.83282632448001, 80.49642666852864, 80.9065316811507]
 - -----------BuyAndSaleNumbers--------------:[9.0, 5.562, 3.437316, 2.124261288, 1.312793475984, 0.8113063681581121, 4.0, 2.472, 1.527696, 0.944116128, 0.5834637671039999, 0.360580608070272]
----------
 - ------------------------------------------
- ###三棵树###
- -----------upPriceStack--------------:[97.51, 107.86, 103.90629999999999, 101.46291339999999, 99.9529004812, 99.0197124973816, 98.44300232338183]
 - -----------downPriceStack--------------:[97.51, 88.25, 91.78732, 93.97338375999999, 95.32437116368, 96.15928137915424, 96.67525589231732]
- -----------BuyAndSaleNumbers--------------:[9.0, 5.562, 3.437316, 2.124261288, 1.312793475984, 0.8113063681581121, 4.0, 2.472, 1.527696, 0.944116128, 0.5834637671039999, 0.360580608070272, 2.0, 1.236, 0.763848, 0.472058064, 0.29173188355199997, 0.180290304035136]
. . . . . . 

issues-7-01

方案2输出结果:

- ###科大讯飞###
 - -----------upPriceStack--------------:[41.88, 47.08, 45.0936, 43.8660048, 43.1073509664, 42.6385028972352, 42.348754790491355]
- -----------downPriceStack--------------:[41.88, 38.52, 39.80352, 40.59673536, 41.086942452479995, 41.38989043563264, 41.57711228922097]
- -----------BuyAndSaleNumbers--------------:[9.0, 5.562, 3.437316, 2.124261288, 1.312793475984, 0.8113063681581121]
----------
 - ###**平安###
- -----------upPriceStack--------------:[81.57, 90.7, 87.21234, 85.05696612, 83.72494506216, 82.90175604841488, 82.3930252379204]
 - -----------downPriceStack--------------:[81.57, 74.21, 77.02152, 78.75903936, 79.83282632448001, 80.49642666852864, 80.9065316811507]
 - -----------BuyAndSaleNumbers--------------:[4.0, 2.472, 1.527696, 0.944116128, 0.5834637671039999, 0.360580608070272]
----------
 - ------------------------------------------
- ###三棵树###
- -----------upPriceStack--------------:[97.51, 107.86, 103.90629999999999, 101.46291339999999, 99.9529004812, 99.0197124973816, 98.44300232338183]
 - -----------downPriceStack--------------:[97.51, 88.25, 91.78732, 93.97338375999999, 95.32437116368, 96.15928137915424, 96.67525589231732]
- -----------BuyAndSaleNumbers--------------:[2.0, 1.236, 0.763848, 0.472058064, 0.29173188355199997, 0.180290304035136]
. . . . . . 

issues-7-02

方案3输出结果:

- ###科大讯飞###
 - -----------upPriceStack--------------:[41.88, 47.08, 45.0936, 43.8660048, 43.1073509664, 42.6385028972352, 42.348754790491355]
- -----------downPriceStack--------------:[41.88, 38.52, 39.80352, 40.59673536, 41.086942452479995, 41.38989043563264, 41.57711228922097]
- -----------BuyAndSaleNumbers--------------:[9.0, 5.562, 3.437316, 2.124261288, 1.312793475984, 0.8113063681581121]
----------
 - ###**平安###
- -----------upPriceStack--------------:[81.57, 90.7, 87.21234, 85.05696612, 83.72494506216, 82.90175604841488, 82.3930252379204]
 - -----------downPriceStack--------------:[81.57, 74.21, 77.02152, 78.75903936, 79.83282632448001, 80.49642666852864, 80.9065316811507]
 - -----------BuyAndSaleNumbers--------------:[4.0, 2.472, 1.527696, 0.944116128, 0.5834637671039999, 0.360580608070272]
----------
 - ------------------------------------------
- ###三棵树###
- -----------upPriceStack--------------:[97.51, 107.86, 103.90629999999999, 101.46291339999999, 99.9529004812, 99.0197124973816, 98.44300232338183]
 - -----------downPriceStack--------------:[97.51, 88.25, 91.78732, 93.97338375999999, 95.32437116368, 96.15928137915424, 96.67525589231732]
- -----------BuyAndSaleNumbers--------------:[2.0, 1.236, 0.763848, 0.472058064, 0.29173188355199997, 0.180290304035136]
. . . . . . 

issues-7-03

方案3效果达到,但Stack内信息堆叠的问题,需要进一步优化解决:最终发现的问题源于StockBuyAndSaleNumbersCompute.java 中的静态变量private static Stack<Double> numbers = new Stack<>();// 买卖黄金率计算数

优化后的最终代码:
StockPriceCompute.java

package com.xxl.job.executor.service.stock;

import com.xxl.job.executor.bean.stock.StockEntity;
import com.xxl.job.executor.dao.stock.StockDao;
import com.xxl.job.executor.utils.GenericStockExcel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;

@Slf4j
@Service
public class StockPriceCompute {
    private static double openingPrice;// 开盘价
    private static double limitUpPrice;// 涨停价
    private static double limitDownPrice;// 跌停价
    private static double triggerUpPrice;// 涨停触发价
    private static double triggerDownPrice;// 跌停触发价
    private static double minRange;// 区间最小幅度
    private static int count = 0;// 计算次数
    private static double goldenRato = 0.618;// 黄金比率
    private double availableNumbers = 0;// 可用股票数
    private int stockTypeNum = 0;// 持有股票种类数

    @Autowired
    private StockEntity stock;
    @Autowired
    private StockDao stockDao;

    public void compute() throws IOException {
        List<StockEntity> stocks = stockDao.findAll();

        List<Stack<Double>> listStockPrice = new ArrayList<>();
        List<String> listStockName = new ArrayList<>();
        Queue<String> stockNameQueue = new LinkedList<String>();

        stockTypeNum = stocks.size();

        for (StockEntity stock : stocks) {
            listStockName.add(stock.getName());

            //添加元素,add()和remove()方法在失败的时候会抛出异常(不推荐)
            stockNameQueue.offer(stock.getName());

            Stack<Double> upPriceStack = new Stack<>();//上涨价集合
            Stack<Double> downPriceStack = new Stack<>();//下跌价集合
            Stack<Double> buyAndSaleNumbers;//

            initBaseData(stock);

//            upPriceStack.clear();
//            downPriceStack.clear();
//            BuyAndSaleNumbers.clear();

            upPriceStack.push(openingPrice);
            upPriceStack.push(limitUpPrice);
            downPriceStack.push(openingPrice);
            downPriceStack.push(limitDownPrice);

            int m = count, n = count;
            while (m > 0) {
                double tempUpBase = upPriceStack.peek();
                upPriceStack.push((1 - goldenRato) * openingPrice + goldenRato * tempUpBase);
                m--;
            }

            while (n > 0) {
                double tempDownBase = downPriceStack.peek();
                downPriceStack.push((1 - goldenRato) * openingPrice + goldenRato * tempDownBase);
                n--;
            }

            buyAndSaleNumbers = StockBuyAndSaleNumbersCompute.computeAvailableNumbers(availableNumbers, count);

            listStockPrice.add(upPriceStack);
            listStockPrice.add(downPriceStack);

            // 方案1
            listStockPrice.add(buyAndSaleNumbers);
            printStockComputeResults(stock, upPriceStack, downPriceStack, buyAndSaleNumbers);
        }
        GenericStockExcel.genericExcelForStockTransaction(listStockPrice, stockNameQueue, stockTypeNum, count);
    }


    private void printStockComputeResults(StockEntity stock, Stack<Double> upPriceStack, Stack<Double> downPriceStack, Stack<Double> buyAndSaleNumbers) {
        log.info("------------------------------------------");
        log.info("###" + stock.name + "###");
        log.info("-----------upPriceStack--------------:" + upPriceStack.toString());
        log.info("-----------downPriceStack--------------:" + downPriceStack.toString());
        log.info("-----------BuyAndSaleNumbers--------------:" + buyAndSaleNumbers.toString());

    }


    public void initBaseData(StockEntity stock) {
        log.info("------------initBaseData------------");

        openingPrice = stock.openingPrice;// 开盘价
        limitUpPrice = stock.limitUpPrice;// 涨停价
        limitDownPrice = stock.limitDownPrice;// 跌停价

        triggerUpPrice = 0;// 涨停触发价
        triggerDownPrice = 0;// 跌停触发价

        count = stock.count;// 计算次数
        availableNumbers = stock.availableNumbers;// 可用股票数
    }
}

StockBuyAndSaleNumbersCompute.java

package com.xxl.job.executor.service.stock;

import java.util.Stack;

public class StockBuyAndSaleNumbersCompute {

    private static double availableNumbers = 0;
    private static double goldenRato = 0.618;// 黄金比率
    
    public static Stack<Double> computeAvailableNumbers(double ownStockNumbers, int count) {
        Stack<Double> numbers = new Stack<>();// 买卖黄金率计算数
        int computCount = count;
        availableNumbers = ownStockNumbers;

        numbers.push(availableNumbers);
        while (computCount > 0) {
            double temp = numbers.peek();
            double tempResult = temp * goldenRato;
            numbers.push(tempResult);
            computCount--;
        }
        return numbers;
    }
}

java: DeadLock 在windows下使用jstack诊断

在windows下使用jstack诊断死锁

  1. 使用命令找出死锁进程pid
$ jps
14080
18836 KotlinCompileDaemon
5160 DeadLockSample
14940 Jps
18956 Launcher
  1. 查看Java堆栈信息
$ jstack 5160
2020-01-28 10:56:10
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.231-b11 mixed mode):

"Thread2" #13 prio=5 os_prio=0 tid=0x0000000027534000 nid=0x4740 waiting for monitor entry [0x00000000291cf000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at geek.bsae.DeadLockSample.run(DeadLockSample.java:19)
        - waiting to lock <0x0000000716657740> (a java.lang.String)
        - locked <0x0000000716657778> (a java.lang.String)

"Thread1" #12 prio=5 os_prio=0 tid=0x000000002752a800 nid=0x1898 waiting for monitor entry [0x00000000290cf000]
   java.lang.Thread.State: BLOCKED (on object monitor)
        at geek.bsae.DeadLockSample.run(DeadLockSample.java:19)
        - waiting to lock <0x0000000716657778> (a java.lang.String)
        - locked <0x0000000716657740> (a java.lang.String)

"Service Thread" #11 daemon prio=9 os_prio=0 tid=0x00000000274d1800 nid=0x19c4 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C1 CompilerThread3" #10 daemon prio=9 os_prio=2 tid=0x0000000027434000 nid=0x4a58 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread2" #9 daemon prio=9 os_prio=2 tid=0x0000000027431000 nid=0x10c waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread1" #8 daemon prio=9 os_prio=2 tid=0x000000002742f000 nid=0x3a14 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" #7 daemon prio=9 os_prio=2 tid=0x0000000027425800 nid=0x564 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Monitor Ctrl-Break" #6 daemon prio=5 os_prio=0 tid=0x000000002740e800 nid=0x2f68 runnable [0x00000000289ce000]
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        at java.net.SocketInputStream.read(SocketInputStream.java:171)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
        at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
        at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
        - locked <0x00000007167cf040> (a java.io.InputStreamReader)
        at java.io.InputStreamReader.read(InputStreamReader.java:184)
        at java.io.BufferedReader.fill(BufferedReader.java:161)
        at java.io.BufferedReader.readLine(BufferedReader.java:324)
        - locked <0x00000007167cf040> (a java.io.InputStreamReader)
        at java.io.BufferedReader.readLine(BufferedReader.java:389)
        at com.intellij.rt.execution.application.AppMainV2$1.run(AppMainV2.java:64)

"Attach Listener" #5 daemon prio=5 os_prio=2 tid=0x0000000027394000 nid=0x1560 waiting on condition [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Signal Dispatcher" #4 daemon prio=9 os_prio=2 tid=0x00000000273ea000 nid=0x3210 runnable [0x0000000000000000]
   java.lang.Thread.State: RUNNABLE

"Finalizer" #3 daemon prio=8 os_prio=1 tid=0x0000000002b4e800 nid=0x55c in Object.wait() [0x00000000286ce000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000716508ed8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:144)
        - locked <0x0000000716508ed8> (a java.lang.ref.ReferenceQueue$Lock)
        at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:165)
        at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:216)

"Reference Handler" #2 daemon prio=10 os_prio=2 tid=0x0000000027373000 nid=0x3424 in Object.wait() [0x00000000285cf000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x0000000716506c00> (a java.lang.ref.Reference$Lock)
        at java.lang.Object.wait(Object.java:502)
        at java.lang.ref.Reference.tryHandlePending(Reference.java:191)
        - locked <0x0000000716506c00> (a java.lang.ref.Reference$Lock)
        at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:153)

"main" #1 prio=5 os_prio=0 tid=0x0000000002a52800 nid=0x47ec in Object.wait() [0x000000000289f000]
   java.lang.Thread.State: WAITING (on object monitor)
        at java.lang.Object.wait(Native Method)
        - waiting on <0x00000007166577b0> (a geek.bsae.DeadLockSample)
        at java.lang.Thread.join(Thread.java:1252)
        - locked <0x00000007166577b0> (a geek.bsae.DeadLockSample)
        at java.lang.Thread.join(Thread.java:1326)
        at geek.bsae.DeadLockSample.main(DeadLockSample.java:34)

"VM Thread" os_prio=2 tid=0x0000000025ca6800 nid=0x2964 runnable

"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002a68000 nid=0x2a64 runnable

"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000002a6a000 nid=0x8cc runnable

"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002a6b800 nid=0x49f0 runnable

"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002a6d000 nid=0x38b8 runnable

"GC task thread#4 (ParallelGC)" os_prio=0 tid=0x0000000002a70000 nid=0x36ec runnable

"GC task thread#5 (ParallelGC)" os_prio=0 tid=0x0000000002a71800 nid=0x42c runnable

"GC task thread#6 (ParallelGC)" os_prio=0 tid=0x0000000002a74800 nid=0x4d38 runnable

"GC task thread#7 (ParallelGC)" os_prio=0 tid=0x0000000002a75800 nid=0x45b8 runnable

"GC task thread#8 (ParallelGC)" os_prio=0 tid=0x0000000002a77000 nid=0xf30 runnable

"GC task thread#9 (ParallelGC)" os_prio=0 tid=0x0000000002a78000 nid=0x2c98 runnable

"VM Periodic Task Thread" os_prio=2 tid=0x00000000274dc000 nid=0x39c4 waiting on condition

JNI global references: 12


Found one Java-level deadlock:
=============================
"Thread2":
  waiting to lock monitor 0x0000000025cb1f18 (object 0x0000000716657740, a java.lang.String),
  which is held by "Thread1"
"Thread1":
  waiting to lock monitor 0x0000000025cb2128 (object 0x0000000716657778, a java.lang.String),
  which is held by "Thread2"

Java stack information for the threads listed above:
===================================================
"Thread2":
        at geek.bsae.DeadLockSample.run(DeadLockSample.java:19)
        - waiting to lock <0x0000000716657740> (a java.lang.String)
        - locked <0x0000000716657778> (a java.lang.String)
"Thread1":
        at geek.bsae.DeadLockSample.run(DeadLockSample.java:19)
        - waiting to lock <0x0000000716657778> (a java.lang.String)
        - locked <0x0000000716657740> (a java.lang.String)

Found 1 deadlock.

redis-error: DENIED Redis is running in protected mode

redis.clients.jedis.exceptions.JedisDataException: DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

	at redis.clients.jedis.Protocol.processError(Protocol.java:132)
	at redis.clients.jedis.Protocol.process(Protocol.java:166)
	at redis.clients.jedis.Protocol.read(Protocol.java:220)
	at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:318)
	at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:236)
	at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:189)
	at com.example.redistest.RedisTestApplicationTests.contextLoads(RedisTestApplicationTests.java:15)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

原因:redis处于保护模式。

解决方案: 可以采取错误提示中的任意一个方式来解决。

  1. Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.

  2. Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.

  3. If you started the server manually just for testing, restart it with the '--protected-mode no' option.

  4. Setup a bind address or an authentication password.

参考链接

Java:@PostConstruct

@PostConstruct 注解总结如下:

从Java EE5规范开始,Servlet中增加了两个影响Servlet生命周期的注解,@PostConstruct和@PreDestroy,这两个注解被用来修饰一个非静态的void()方法。写法有如下两种方式:

@PostConstruct
public void someMethod(){}

或者

public @PostConstruct void someMethod(){}

@PostConstruct修饰的方法会在服务器加载Servlet的时候运行,并且只会被服务器执行一次。PostConstruct在构造函数之后执行,init()方法之前执行。PreDestroy()方法在destroy()方法知性之后执行

PostConstruct-exc

另外,spring中Constructor、@Autowired@PostConstruct 的顺序

其实从依赖注入的字面意思就可以知道,要将对象p注入到对象a,那么首先就必须得生成对象a和对象p,才能执行注入。所以,如果一个类A中有个成员变量p被@Autowried注解,那么@Autowired注入是发生在A的构造方法执行完之后的。

如果想在生成对象时完成某些初始化操作,而偏偏这些初始化操作又依赖于依赖注入,那么久无法在构造函数中实现。为此,可以使用@PostConstruct注解一个方法来完成初始化,@PostConstruct注解的方法将会在依赖注入完成后被自动调用。

Constructor >> @Autowired >> @PostConstruct

举个栗子:

public Class AAA {

    @Autowired
    private BBB b;

    public AAA() {
        System.out.println("此时b还未被注入: b = " + b);
    }

    @PostConstruct
    private void init() {
        System.out.println("@PostConstruct将在依赖注入完成后被自动调用: b = " + b);
    }
}

提示:静态方法中调用非静态方法。好像也需要如此处理?

redis-error: windows10链接本机虚拟机redis链接不上的解决方法

redis.clients.jedis.exceptions.JedisConnectionException: Failed connecting to host 192.168.35.136:6379

	at redis.clients.jedis.Connection.connect(Connection.java:204)
	at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:100)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:125)
	at redis.clients.jedis.Connection.sendCommand(Connection.java:120)
	at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:113)
	at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:188)
	at com.example.redistest.RedisTestApplicationTests.contextLoads(RedisTestApplicationTests.java:15)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.util.ArrayList.forEach(ArrayList.java:1257)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: java.net.SocketTimeoutException: connect timed out
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
	at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
	at java.net.Socket.connect(Socket.java:606)
	at redis.clients.jedis.Connection.connect(Connection.java:181)
	... 69 more

原因: 绑定端口未注释,防火墙端口没有启用。

解决方案

  1. 注释redis.conf中的绑定地址
# bind 127.0.0.1
  1. 开启服务器6379端口的防火墙
[xiecentos@xiecentos ~]$ firewall-cmd --query-port=6379/tcp
no
[xiecentos@xiecentos ~]$ firewall-cmd --zone=public --add-port=6379/tcp --permanent
success
[xiecentos@xiecentos ~]$ firewall-cmd --query-port=6379/tcp
no
[xiecentos@xiecentos ~]$ firewall-cmd --reload
success
[xiecentos@xiecentos ~]$ firewall-cmd --query-port=6379/tcp
yes

参考链接地址

RabbitMQ: could_not_start_listener,"::",5672,eaddrinuse

报错:

Application rabbit exited with reason: {{could_not_start_listener,"::",5672,eaddrinuse},{rabbit,start,[normal,[]]}}

配置文件中不能同时配置这两个选项

# listeners.tcp.default = 5672

# listeners.tcp.local    = 127.0.0.1:5672

redis-error: stop-writes-on-bgsave-error option

(error) MISCONF Redis is configured to save RDB snapshots, but it is currently not able to persist on disk. Commands that may modify the data set are disabled, because this instance is configured to report errors during writes if RDB snapshotting fails (stop-writes-on-bgsave-error option). Please check the Redis logs for details about the RDB error.

原因:强制关闭Redis快照导致不能持久化。

解决方案
运行config set stop-writes-on-bgsave-error no 命令后,关闭配置项stop-writes-on-bgsave-error解决该问题。或者修改配置文件,重新启动redis服务。

Java: Mybatis Invalid bound statement (not found)

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

该问题可能存在于mybatis中dao接口与mapper配置文件在做映射绑定的时候出现问题,简单说,就是接口与xml要么是找不到,要么是找到了却匹配不到。

问题排查解决方案(参考):

  1. 检查xml文件的命名空间是否和Mapper interface所在的包名对应
<mapper namespace="com.xxl.job.executor.dao.stock.StockDao">
  1. XxxDao.java的方法在XxxMapper.xml中不存在,然后执行XxxDao.java中的方法会报此错误
  2. XxxDao的方法返回值是List,而select元素没有正确配置ResultMap,或者只配置ResultType
  3. 如果确认没有以上问题,建议重新写一边xml文件,可能存在特殊字符
  4. 看一下项目的配置文件,关于Mybatis的映射路径是否正确
### mybatis
mybatis.mapper-locations=classpath:/mybatis/mapper/*Mapper.xml
  1. 有关于@Mapper和@MapperScan的相关知识请参考

Java: common-tomcat-maven-plugin-pom-3.0-r1655215

Could not transfer artifact org.apache.tomcat.maven:common-tomcat-maven-plugin:pom:3.0-r1655215 from/to Alfresco (https://artifacts.alfresco.com/nexus/content/repositories/public/): GET request of: org/apache/tomcat/maven/common-tomcat-maven-plugin/3.0-r1655215/common-tomcat-maven-plugin-3.0-r1655215.pom from Alfresco failed

    <build>
        <plugins>
            <!-- Tomcat 8 Maven 插件用于构建可执行 war -->
            <!-- https://mvnrepository.com/artifact/org.apache.tomcat.maven/tomcat8-maven-plugin -->
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat8-maven-plugin</artifactId>
                <version>3.0-r1655215</version>
                <executions>
                    <execution>
                        <id>tomcat-run</id>
                        <goals>
                            <!-- 最终打包成可执行的jar包 -->
                            <goal>exec-war-only</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                            <!-- ServletContext 路径 -->
                            <path>/</path>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <!-- tomcat8-maven-plugin 所在仓库 -->
            <id>Alfresco</id>
            <name>Alfresco Repository</name>
            <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

tomcat-maven-plugin-pom-3-0-r1655215

解决方案

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.