Giter VIP home page Giter VIP logo

concurrent-in-action's Introduction

concurrent-in-action

并发编程实践学习

自定义注解

  • com.xkcoding.concurrentinaction.annotation.Recommend 用于标记【推荐】的类
  • com.xkcoding.concurrentinaction.annotation.UnRecommend 用于标记【不推荐】的类
  • com.xkcoding.concurrentinaction.annotation.ThreadSafe 用于标记线程【安全】的类
  • com.xkcoding.concurrentinaction.annotation.ThreadUnSafe 用于标记线程【不安全】的类

并发测试类

需要进行并发安全测试的类,可以直接继承 com.xkcoding.concurrentinaction.base.AbstractConcurrentTest 这个类,重写 AbstractConcurrentTest#testMethod() 这个方法,在里面运行调用待测试的方法,然后执行 AbstractConcurrentTest#execute() 即可开始并发测试。

示例 demo:

package com.xkcoding.concurrentinaction.notsafe;

import com.xkcoding.concurrentinaction.annotation.ThreadUnSafe;
import com.xkcoding.concurrentinaction.base.AbstractConcurrentTest;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>
 * 并发下int累加
 * </p>
 *
 * @package: com.xkcoding.concurrentinaction.notsafe
 * @description: 并发下int累加
 * @author: yangkai.shen
 * @date: Created in 2018/8/23 下午11:27
 * @copyright: Copyright (c) 2018
 * @version: V1.0
 * @modified: yangkai.shen
 */
@ThreadUnSafe
@Slf4j
public class ConcurrentIntAdd extends AbstractConcurrentTest {

	private int count = 0;

	public static void main(String[] args) throws Exception {
		ConcurrentIntAdd test = new ConcurrentIntAdd();
		// 执行测试方法
		test.execute();
		log.info("count:{}", test.count);
	}

	private void add() {
		count++;
	}

	/**
	 * 测试方法
	 */
	@Override
	public void testMethod() {
		add();
	}
}

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.