陈志军

物来顺应,未来不迎,当时不杂,既过不恋


  • 首页

  • 分类

  • 归档

  • 标签

  • 搜索

随笔-8-19

发表于 2017-08-19 | 分类于 Question | 阅读次数

8月19日 阶段总结

日期格式?

SimpleDateFormat ===> SimpleDateFormat

Double 后面有个E?

A: double 为啥后面有个E ,E后面的数字代表后面乘以10的位数

java 格式化金额显示

A: numberFormat,留4位小数:

1
2
3
4
5
6
7
8
9
10

public static final int DEFAULT_FORMAT = 4;

public static String formatCurrency(Double money)
{
NumberFormat numberFormat = NumberFormat.getNumberInstance();
numberFormat.setMaximumFractionDigits(DEFAULT_FORMAT);
return numberFormat.format(money);
}

查看服务器上java命令位置:

A: whereis javac/java ls -al 一直找到没有软连接位置

jenkins 构建的时候,nohup: failed to run command 没有找到目录,没有权限

A: jenkins启动springboot脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/bash
source /etc/profile
#pname=$1
pname=com.apec.warehouse-server-1.0-RELEASE.jar
puser=root
pid=`ps aux | grep $pname | grep $puser | grep -v grep | awk '{print $2}'`

if [[ -z $pid ]]; then
echo "I can NOT find $pname running by $puser"
fi
#/home/cncsen/warehouse/com.
chmod 777 /home/cncsen/warehouse/com.apec-warehouse-server-1.0-RELEASE.jar
kill -9 $pid >/dev/null 2>&1
cd /home/cncsen/warehouse/
exec nohup java -Xmx128m -Xss256k -jar $pname --cacheType=single --spring.profiles.active=test 5 >>server.log &
tail -f server.log

使用jenkins对springboot进行CI

发表于 2017-08-10 | 阅读次数

写给小白看的jenkins CI教程

目标

使用jenkins持续部署一个springboot项目,项目使用jar包发布.从安装jenkins的机器将jar包发布到指定的服务器目录,并且使用脚本运行springboot. (前面几张图可能看不见,以后补上)

个人背景

Java工程师毕业一年,Linux一般熟悉,Java初阶,所以不用担心难度,如果有疑问可以联系我:vbookchen@gmail.com

系统环境与准备

jenkins就是相当于一个web服务,与环境没有太大关系

  1. Linux/Windows 操作

  2. jenkins.jar/jenkins.msi //安装就是了,其他的是系统可以下载war包在tomcat里面运行

  3. gitlab.com 账号

  4. gitlab 公有仓库放置 spring-boot 源码

  5. maven // 可以用jenkins安装也可以用本地的

  6. JDK 安装jenkins的主机必须要有jdk, docker版本除外

  7. 部署服务的Linux服务器

阅读全文 »

java-基础之string

发表于 2017-08-08 | 分类于 Java | 阅读次数

Java 基础-String

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class.

`String`类包括了一系列字符的方法,比如:比较字符,查找字符,子字符串,创建一个全是大写或者全是小写的字符。匹配是在unicode标准版本规范在`Character` 类的基础上。

The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java. For additional information on string concatenation and conversion, see Gosling, Joy, and Steele, The Java Language Specification.

Java语言提供了对字符的操作符`+`做了特殊的支持,并且对其他的objects转换成string也做了相应支持。String的连接是StringBuilder(或者说StringBuffer)来实现的它的append方法的。String转换是通过实现定义在Object(所有的java方法都继承了它)的toString方法。更多的额外的字符操作和转换的特殊操作,看看gosling,joy,steele,写的《java语言规范》。

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

除非有额外的标记,传递一个null参数给一个构造方法或者非构造方法在这个类中,会导致`NullPointerException`被抛出。

A String represents a string in the UTF-16 format in which supplementary characters are represented by surrogate pairs (see the section Unicode Character Representations in the Character class for more information). Index values refer to char code units, so a supplementary character uses two positions in a String.

一个String呈现的字符串是用UTF-16格式,不够的补位。

The String class provides methods for dealing with Unicode code points (i.e., characters), in addition to those for dealing with Unicode code units (i.e., char values).

这个String类提供方法处理Unicode代码点和unicode代码单元。

阅读全文 »

apec-804-problem

发表于 2017-08-04 | 分类于 Question | 阅读次数

7月25日问题

Persistable QModel生成。?

A: 其实这是一个QSL框架生成的,所有Entity都会生成一个QEntity类。

8月1日问题

maven complier install package 的区别?

A:complier只是编译,不会生成jar包,package生成jar包,但是不会将包发布到仓库,只在项目下,install会将jar包发布到仓库让别人也可以用

maven install 跳过测试?

A: 执行的时候加上 -Dmaven.test.skip=true

jpa 插入枚举值得时候默认为1?

A:默认使用 ordinal 值,其实应该为string

maven 设置java版本?

A: pom文件中加入:

1
2
3
4
5
6
7
8
9
10
11
12
13
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

springboot 使用jrebel热加载?

A: 现在pom文件里面加入devtools: 之后使用ctrl+alt+shift+/ 选中Registry 勾上app.running

1
2
3
4
5
6
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

8月3日问题

SimpleDateFormate 日期格式类使用注意?

A:日期工具类里面使用了SimpleDataFormate=> format方法里面有个calendar.setTime(date);.
如果是多线程中,这个方法没有做同步Thread-A,有一个date,然后Thread-B有一个date,那么造成出现预料之外的结果,当然这种情况出现在共享一个SimpleDateFormate当中,既设置一个全局的simpleDateformat。如果在方法中设置局部变量的simpledateformate,那么局部变量是线程安全的。
当然追求效率可以使用ThreadLocal,设置局部缓存

Java 反射获取属性?

A:注解是分为执行状态(运行,编译),执行位置(类,方法,属性),如果用declared, 包括所有非父类属性。如果不用declared,获取所有为public的属性
getFields()===> 获取所有属性为public的
getDeclaredFields()===> 获取所有非继承的数据(public,protect,default….)

问题总结

发表于 2017-07-24 | 分类于 Question | 阅读次数

Java问题总结

7-14

  1. idea编码不一致

A: FileEncoding –>globalEncode&&projectEncoding–>Default encoding for properties UTF-8
所有项目尽量一开始就设置UTF-8再导入项目

  1. idea vim插件冲突的问题,

A:直接设置vim emulation。 将handler全部改为ide

  1. redis.clients.jedis.exceptions.JedisConnectionException: no reachable node in cluster

A: 没有找到可以用的redis集群

  1. idea 查看当前类的信息

A: alt+Q 可以快速查看当前是哪个类

  1. idea ctrl+o 重写某个方法

7-15

  1. spring定时任务, CRON表达式 */5 * * * * ?

A:CRON的格式是固定的,如果需要在spring中开启定时任务,给类加上@Service注入,然后在方法上加入@Scheduled(cron = "*/5 * * * * ?")就可以了开启一个定时任务了。

  1. java list排序自定义

A:如果有需求需要自己给list里面的对象设置排序。可以重写方法。

1
2
3
4
5
6
7
8
Collections.sort(pushData, (AppTips o1, AppTips o2) ->
{
if(o1.getCreateDate().before(o2.getCreateDate()))
{
return 1;
}
return 0;
});
  1. java传入引用,没有修改值,传入一个list到方法里面,在方法里面修改了list,之后list的值没有改变,引起误解为啥传入对象,修改了对象的值而没有改变对象内容。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.ArrayList;
import java.util.List;

public class ListTest
{
public static void main(String[] args)
{
List<String> a = new ArrayList<String>();
a.add("adf");
a.add("werwerwe");

List<String> b = new ArrayList<>();
setB(b);
System.out.println(b.isEmpty()); // true

setB2(a,b);
System.out.println(b.isEmpty()); // false


}


private static void setB(List<String> b)
{
b=new ArrayList<>();
b.add("test1");
b.add("tet2");
}

private static void setB2(List<String> a,List<String> b){
b.addAll(a);
}
}

A: 其实Java除基本类型之外,其他的都为引用传递。这是对的,在上面的例子中,因为在setB中,我们将引用b重新指定到了一个对象new ArrayLsit<>()所以b此时已经不再指向原来的空间了。

  1. redis有一个database

A: 一开始直接用redis-cli,用keys *发现没有值可以获取,但是代码里面可以获取到值,后来发现其实springboot做了设置redis.database=4。其实在redis客户端里面使用select 4就可以了。

7-21

1)requestParam 参数可以放在body里面

2)nested exception is java.lang.IllegalArgumentException: Not enough variable values available to expand

A: 这个异常耽误了我半天的时间,后来发现其实是restTemplate使用的时候url不要拼接json串,因为它遇到{}会认为是一个变量,然后去解析值。详情

klook-607-problem

发表于 2017-06-07 | 分类于 Question | 阅读次数

年度问题日结,将今年每天遇到的问题做一个记录: <月.日 问题>

6.7 问题

  1. Hashmap寻找的时间复杂度

    hashmap的实现是”数组+链表”的形式,

    1
    2
    3
    4
    1. 先根据key值计算出hash值以及h值(h值是java实现中处理得到的更优的index索引值)
    2. 查找table数组中的h位置,得到相应的键值对链表
    3. 根据key值,遍历键值对链表,找到相应的键值对,
    4. 从键值对中取出value值。
  2. Golang 反射将数字转成float64

    value.(float64)

  3. Golang map判断是否有键值

    if val,ok:=map[key];ok{

     // 有值
    

    }

阅读全文 »

Docker 网络

发表于 2017-05-14 | 分类于 Docker | 阅读次数

有了底层,有了数据,还差一个网络基础配置,那样就完美了

1,宿主机和Docker容器端口对应

docker run -ti --name test-network -d -p 50001:8080 chenzhijun/javaweb:1.0 或者用 docker run -ti --name test-network -d -p 50001:8080 chenzhijun/javaweb:1.0 /root/run.sh

创建一个在chenzhijun/javaweb:1.0镜像上的test-network容器,并且将本地的50001端口映射到docker的8080端口。chenzhijun/javaweb:1.0 镜像可以在hub.docker.com上下载,进入到容器后,进入root文件夹下,启动run.sh。然后再本地就可以用localhost:50001端口访问了。

阅读全文 »

Docker 数据管理

发表于 2017-05-13 | 分类于 Docker | 阅读次数

Docker 的数据管理应该核心中的核心。因为不管哪个公司,数据应该永远是第一位。

1,Docker 数据卷简介

Docker 的数据卷是一个可供容器使用的特殊目录,它绕过文件系统,提供很多的特性:

  • 数据卷可以在容器之间共享和重用
  • 对数据卷的修改会立马生效
  • 对数据卷的更新,不会影响镜像
  • 卷会一直存在,直到没有容器使用
    数据卷的使用,类似于Linux下对目录或文件进行mount操作。
    阅读全文 »

Docker 容器

发表于 2017-05-13 | 分类于 Docker | 阅读次数

Docker 容器

容器是 Docker 的另一个核心概念

容器是镜像的一个运行实例,所不同的是,它带有额外的可写文件层

1,创建容器

docker create -it centos:latest 新建的容器处于停止状态,可以用 docker start 命令来启动它。

2,新建并启动容器

docker run centos /bin/echo 'Hello world' ,输出了Hello world,之后就没了,使用 docker ps 看不到容器运行。

阅读全文 »

Docker 镜像

发表于 2017-05-13 | 分类于 Docker | 阅读次数

镜像是Docker的三大核心概念之一。

Docker运行容器前需要本地存在对应的镜像,Docker会尝试先从默认镜像仓库下载,可以自定义默认仓库位置。

1,获取镜像

docker pull name[:TAG],如果TAG没有的话,默认是latest。
获取到镜像后,就可以使用镜像创建容器,在其中运行bash应用。

2,查看镜像信息

docker images,列出本地主机上已有的镜像。
docker tag dl.dockerpull.com:5000/ubuntu:latest ubuntu:latest,给本地镜像添加新标签,新标签的镜像id是一样的。
docker inspect image-id,获取image-id的详细信息,json串。如果只想要某个信息的话,可以用
docker inspect -f {{".RootFS"}} 48b5,RootFS是json的某一项内容的详情。48b5,是镜像id。

阅读全文 »
1…15161718

180 日志
41 分类
70 标签
RSS
GitHub GitEE
推荐阅读
  • 陈志军的个人站
© 2017 - 2023 陈志军
由 Hexo 强力驱动
主题 - NexT.Muse