首页 > 代码库 > JAVA线程间共享变量

JAVA线程间共享变量

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class ThreadScopeShareData {


	static Map<Thread, Integer> dataMap = new HashMap<Thread, Integer>();

	public static void main(String[] args) {

		for (int i = 0; i < 2; i++) {
			new Thread(new Runnable() {

				@Override
				public void run() {
					int data = http://www.mamicode.com/new Random().nextInt(100);>
更多内容请关注公众号