Spring Async 实现 ForkJoin

第一种情况,Service类:

@Async
public String test1() {
    String threadName = Thread.currentThread().getName();
    log.error("{}: 1 start", threadName);
    try {
        Thread.sleep(5000L);
    } catch (Exception e){
    }
    log.error("{}: 1 end", threadName);
    return "s1";
}

@Async
public String test2() {
    String threadName = Thread.currentThread().getName();
    log.error("{}: 2 start", threadName);
    try {
        Thread.sleep(2000L);
    } catch (Exception e){
    }
    log.error("{}: 2 end", threadName);
    return "s2";
}

Controller类:

try {
    String threadName = Thread.currentThread().getName();
    log.error("{}: 0 start", threadName);
    PrintWriter out = response.getWriter();
    String f1 = testService.test1();
read more

springBoot数据库连接池常用配置

在配置文件中添加配置如下(这里使用的是多数据源):

spring.datasource.primary.url=jdbc\:mysql\://localhost\:3306/test?useUnicode\=true&characterEncoding\=utf-8
spring.datasource.primary.username=test
spring.datasource.primary.password=123456
spring.datasource.primary.driver-class-name=com.mysql.jdbc.Driver
#验证连接的有效性
spring.datasource.primary.test-while-idle=true
#获取连接时候验证,会影响性能
spring.datasource.primary.test-on-borrow=false
#在连接归还到连接池时是否测试该连接
spring.datasource.primary.test-on-return=false
spring.datasource.primary.validation-query=SELECT 1 FROM DUAL
#空闲连接回收的时间间隔,与test-while-idle一起使用,设置5分钟
read more

简单粗暴的用树莓派驱动USB打印机

先把打印机用usb线接到树莓派上,然后在树莓派执行 lsusb 命令,这个时候会列表连接上的所有usb设备,如下:

1
2
3
4
5
6
Bus 005 Device 001: ID 0000:0000
Bus 001 Device 001: ID 0000:0000
Bus 004 Device 001: ID 0000:0000
Bus 003 Device 001: ID 0000:0000
Bus 002 Device 006: ID 15d9:0a37
Bus 002 Device 001: ID 0000:0000

这个时候不知道谁是打印机呢!不过不要紧,你拔掉打印机的usb线后再执行一次,看缺谁,谁就是打印机了。

ID后冒号隔开的两个数字就是usb设备的 vendor ID和product Id了,记下来先,一会儿连接的时候有大用。

为了连接打印机,你需要安装python-usb这个库,用于直接通过usb接口来操作usb设备。本文的第一个坑就出在这里,因为pip库里的版本有一个bug的方式在后面的库会用到,所以必须用从github里最新的去除了bug的代码里安装才不会出问题。所以只能用这样子的方式来安装才行。

1
2
3
git clone https://github.com/walac/pyusb.git
cd pyusb
python setup.py install

安装好后我们就可以通过usb接口来操作打印机了,由于大多数打印机都支持EPSON的打印协议(很古老的协议了,所以到处都支持),所以我们可以安装一个叫python-escpos read more

centos7下使用yum安装mysql

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源。

1. 下载mysql的repo源

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. 安装mysql-community-release-el7-5.noarch.rpm包

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm

安装这个包后,会获得两个mysql的yum read more

linux bugzilla nginx 安装配置 详解

Bugzilla是Mozilla公司提供的一款开源的免费Bug追踪系统,用来帮助你管理软件开发,建立完善的BUG跟踪体系。

在网上看了一下,bugzilla的安装,大部分的web环境是apache 。下面说一下我的安装过程。

一,安装epel源

请参考:centos 推荐使用epel源

二,安装mysql nginx bugzilla,以及相关工具

  1. yum install mysql mysql-server bugzilla fcgi-devel fcgi nginx perl spawn-fcgi

安装fcgiwrap,它是用来运行perl的cgi程序的

fcgiwrap下载地址: http://github.com/gnosek/fcgiwrap/tarball/master

  1. [root@localhost download]# tar zxvf gnosek-fcgiwrap-1.1.0-5-g66e7b7d.tar.gz
  2. [root@localhost download]# cd gnosek-fcgiwrap-66e7b7d/
  3. [root@localhost gnosek-fcgiwrap-66e7b7d]# autoreconf -i
  4. [root@localhost gnosek-fcgiwrap-66e7b7d]# ./configure
  5. [root@localhost gnosek-fcgiwrap-66e7b7d]# make
  6. gcc -std=gnu99 -Wall -Wextra -Werror -pedantic -O2 -g3 fcgiwrap.c -o fcgiwrap -lfcgi
  7. [root@localhost gnosek-fcgiwrap-66e7b7d]# cp fcgiwrap /usr/local/bin/

如果autoreconf -i时,autoreconf命令不存在,安装如下依赖包:

  1. yum install patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel

三,启动mysql,并创建bugzilla数据库

  1. /etc/init.d/mysqld start   //启动服务端
  2. mysql> create database bugstest;    //创建空数据库
  3. mysql> grant all privileges on bugstest.* TO ‘bugstest’@‘localhost’ IDENTIFIED BY ‘bugstest’;   //分配权限
  4. mysql> flush privileges;

四,修改bugzilla的配置localconfig,并且安装bugzilla数据库

1,修改/etc/localconfig

  1. $db_name = ‘bugstest’;      //数据库名
  2. $db_user = ‘bugstest’;      //连接用户名
  3. $db_pass = ‘bugstest’;        //连接密码

就是上面,mysql里面添加的用户。

read more

SQL中inner join、outer join和cross join的区别

Table A 是左边的表。Table B 是右边的表。
Table A 是左边的表。Table B 是右边的表。

对于SQL中inner join、outer join和cross join的区别很多人不知道,我也是别人问起,才查找资料看了下,跟自己之前的认识差不多,如果你使用join连表,缺陷的情况下是inner join,另外,开发中使用的left join和right join属于outer join,另外outer join还包括full join.下面我通过图标让大家认识它们的区别。
现有两张表,Table A 是左边的表。Table B 是右边的表。其各有四条记录,其中有两条记录name是相同的:

1.INNER JOIN 产生的结果是AB的交集

SELECT * FROM TableA INNER JOIN TableB ON TableA.name = TableB.name
          
2.LEFT [OUTER] JOIN 产生表A的完全集,而B表中匹配的则有值,没有匹配的则以null值取代。
read more

java中RSA加解密的实现

public static void main(String[] args) throws Exception {  
        // TODO Auto-generated method stub  
        HashMap<String, Object> map = RSAUtils.getKeys();  
        //生成公钥和私钥  
        RSAPublicKey publicKey = (RSAPublicKey) map.get("public");  
        RSAPrivateKey privateKey = (RSAPrivateKey) map.get("private");  
          
        //模  
        String modulus = publicKey.getModulus().toString();  
        //公钥指数  
        String public_exponent = publicKey.getPublicExponent().toString();  
        //私钥指数  
        String private_exponent = privateKey.getPrivateExponent().toString();  
        //明文  
        String ming = "123456789";  
        //使用模和指数生成公钥和私钥
read more

Android SSL BKS证书的生成过程

在用Android平台上使用SSL,第一步就是生成证书。

1、证书的生成

1.1生成服务器端的证书

keytool -genkey -alias test -keystore test.jks

1.2 将keystore中的cert导出来,用来生成客户端的验证证书

keytool -exportcert -alias test -file test.cert -keystore test.jks

1.3 生成Android平台的证书

read more

hibernate用hbm2java给pojo增加serialVersionUID

Hibernate 3.2.x 工具中hbm2java生成的pojo类总是类似下面:

public class Child implements java.io.Serializable {
 private int cid;
 private String childName;
 public int getCid() {
 return this.cid;
 }
 public void setCid(int cid) {
 this.cid = cid;
 }
 public String getChildName() {
 return this.childName;
 } 
 public void setChildName(String childName) {
 this.childName = childName;
 }
}

但是如果你使用JDK5.0或更高版本时,总是警告该类缺少个static final long serialVersionUID,如何才能在hbm2java生成java源代码时自动加上呢?这就要修改hibernate-tools.jar中自带的pojo模板了。

首先,你将hibernate-toosl.jar中的pojo/Pojo.ftl文件解压出来,在<#if !pojo.isInterface()>的下一行增加:static final long serialVersionUID = 1L;增加后整个Pojo.ftl文件内容应该是这样:

${pojo.getPackageDeclaration()}
// Generated ${date} by Hibernate Tools ${version}
<#assign classbody>
<#include "PojoTypeDeclaration.ftl"/> {
<#if !pojo.isInterface()>
static final long serialVersionUID = 1L;
<#include "PojoFields.ftl"/>
<#include "PojoConstructors.ftl"/>
 
<#include "PojoPropertyAccessors.ftl"/>
<#include
read more

HL7 2.X解析 for C#版

Hl7引擎的目标主要是解决将数据按HL7协议的要求标准化,和标准业务的集成和不同系统间标准业务数据的同步。在多年的医院集成平台信息化过程中,HL7标准组织和解析最复杂了,下面是我用了多年HL7引擎解析,因公司升级使用了HL73.0版本,决定把HL72.X引擎放到博客上保存。

(引擎解析类)Decode.cs

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Text.RegularExpressions;

namespace com.china.hl7 {
    /// <summary>
    /// HL7解析器
    /// </summary>
    public static class HL7ToXmlConverter {
        private static XmlDocument _xmlDoc;

        /// <summary>
        /// 把HL7信息转成XML形式
        /// 分隔顺序 \n,|,~,^,&
        /// </summary>
        /// <param name="sHL7">HL7字符串</param>
        /// <returns></returns>
        public static string ConvertToXml(string sHL7) {
            _xmlDoc = ConvertToXmlObject(sHL7);
            return _xmlDoc.OuterXml;
        }

        public static
read more