分类 技术 下的文章

实现Runnable接口

public class FirstThread implements Runnable {

    @Override
    public void run() {
        System.out.println("first thread run...");
    }
}

new Thread(new FirstThread().start())

继承Thread类

Thread类本身就是实现的Runnable接口: Thread implements Runnable

public class SecondThread extends Thread {

    @Override
    public void run() {
        System.out.println("second thread run...");
    }
}
new Thread(new SecondThread().start())

实现Callable接口来创建Thread线程

- 阅读剩余部分 -

package cn.gl.work;

/**
 * Created by guoli on 2017/9/9 0009.
 * YXV0aG9yOiB6aGFuZ2d1b2xpLmNu
 */
public class StringIndexOf {

    public int IndexOf(String source, String target) {
        char[] sources = source.toCharArray();
        char[] targets = target.toCharArray();
        int sourceCount = sources.length;
        int targetCount = targets.length;
        char first = targets[0];
        int max = sourceCount - targetCount;
        for (int i = 0; i <= max; i++) {
            //1. 第一个字符相等
            if (sources[i] != first) {
                while (++i < max && sources[i] != first) {
                    ;
                }
            }
            //2、匹配2到子串
            if (i < max) {//未到最后
                int j = i + 1;
                int end = j + targetCount - 1;
                for (int k = 1; j < end && sources[j] == targets[k]; j++, k++) {
                    ;//子串和原串截取的部分在循环对比
                }
                if (j == end) {//找到了
                    return i;
                }
            }
        }
        return -1;
    }
}

执行顺序如下所示,原因太长就不写了

(8) SELECT <select_list>
(9) DISTINCT <select_list>
(1) FROM <left_table>
(3) <join_type> JOIN <right_table>
(2) ON <join_condition>
(4) WHERE <where_condition>
(5) GROUP BY <group_by_list>
(6) WITH {CUBE|ROLLUP}
(7) HAVING <having_condition>
(10) ORDER BY <order_by_list>
(11) LIMIT <limit_number>

这里看到一个SQL题目:查询学生总成绩的前三名,给出MySQL和Oracle的写法

学生总成绩前三名

INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('nick', 'yuwen', 88);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('jack', 'shuxue', 95);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('nick', 'shuxue', 68);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('jack', 'yuwen', 96);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('susan', 'yuwen', 100);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('susan', 'shuxue', 95);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('lee', 'yuwen', 100);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('lee', 'shuxue', 95);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('zhang', 'yuwen', 58);
INSERT INTO `student_grade`(`name`, `course`, `grade`) VALUES ('zhang', 'shuxue', 91);

MySQL使用LIMIT关键字:

SELECT name
FROM student_grade
GROUP BY name
ORDER BY sum(grade) DESC
LIMIT 0,3

Oracle使用ROWNUM关键字

select name FROM(
    SELECT name
    FROM student_grade
    GROUP BY name
    ORDER BY sum(grade) DESC
)WHERE rownum <=3;

本文内容有误,不建议参考。

操作环境:CentOS 6.5MySQL 5.*

1、查看是否安装MySQL

yum list installed | grep mysql

2、卸载自带MySQL

一般的Linux发行版会自带MySQL,但是主机服务商提供的Linux发行版不带MySQL,如果主机上没有安装MySQL则忽略此处

yum -y remove mysql-libs.x86_64

如果存在多个依赖文件也一并卸载

3、安装MySQL

yum -y install mysql-server mysql mysql-devel

如果提示No package *** available不可用,则增加MySQL repo

vim /etc/yum.repos.d/mysql-community.repo

增加如下内容:

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=

重新安装MySQL

- 阅读剩余部分 -

execution(returnType package.class.method(param)

1、returnType

返回类型: public String、private int

2、package.class.method

包.类.方法均可用*代替,例如: *.class.methodpackage.class.**

3、 param:

()匹配了一个不接受任何参数的方法

(..)零或者更多个任意类型参数的方法
(*)一个任意类型的参数方法


- 阅读剩余部分 -

演员演出需要记录每个演员的演出次数

1. Performance接口和Actor类

package aop;

/**
 * Created by guoli on 2017/7/28 0028.
 * YXV0aG9yOiB6aGFuZ2d1b2xpLmNu
 */
public interface Performance {

    /**
     * @param number 演员编号
     */
    public void playTrack(String number);
}
package aop;

import org.springframework.stereotype.Component;

/**
 * Created by guoli on 2017/7/28 0028.
 * YXV0aG9yOiB6aGFuZ2d1b2xpLmNu
 */
@Component
public class Actor implements Performance {

    @Override
    public void playTrack(String number) {
        System.out.println(number + " number actor");
    }
}

- 阅读剩余部分 -

1. 表演接口Performance 和舞台剧LivingTheatre

package concert;

/**
 * ①普通Java类
 * Created by guoli on 2017/7/23 0023.
 * YXV0aG9yOiB6aGFuZ2d1b2xpLmNu
 */

/**
 * Performance只是一个普通的Java接口
 * 使用如下切点表达式可以设置当perform()方法执行时触发通知的调用
 * execution(*  concert.LivingTheatre.perform(..))
 * 切点表达式解释如下:
 * execution 在方法执行时触发
 * *任意返回值类型
 * concert.LivingTheatre.perform 包-类/接口-方法
 * .. 任意参数
 */
public interface Performance {
    public void perform();
}
package concert;

import org.springframework.stereotype.Component;

/**
 * ②实现Performance接口的普通类
 * Created by guoli on 2017/7/23 0023.
 * YXV0aG9yOiB6aGFuZ2d1b2xpLmNu
 */

/**
 * @Component泛指组件,和@Controller、@Service、@Repository在大多数情况下是通用的
 */
@Component
public class LivingTheatre implements Performance {

    @Override
    public void perform() {
        System.out.println("kaixinmahua........");
    }
}

2. 切点表达式

切点表达式基础知识

- 阅读剩余部分 -

1. 下载Nginx for Windows压缩包

访问http://nginx.org/en/download.html ,或直接下载http://nginx.org/download/nginx-1.8.1.zip

2. 解压到特定目录,进入该目录

此处为 D:Program Filesnginx-1.8.1

3. 运行命令行 start nginx

4. 查看状态 tasklist /fi "imagename eq nginx.exe"

5. 重新加载配置文件 nginx -s reload

nginx -s stop 强制停止
nginx -s quit "关机"

Linux下Nginx的安装:http://zhangguoli.cn/linux-nginx-install.html

Linux下启动Tomcat报错:

ERROR:java.lang.InternalError: Can't connect to X11 window server using 'localhost:11.0' as the value of the DISPLAY variable.

查询得知是因为linux上没有启动x server。

解决办法

1、 修改tomcat/bin/catalina.sh

在所有的-Dcatalina.home="$CATALINA_HOME" /后面增加-Djava.awt.headless=true \

 -Dcatalina.home="\"$CATALINA_HOME\"" \
 -Djava.awt.headless=true  \

2、export DISPLAY=:0