package ifeve;public class ConcurrencyTest {private static final long count = 100000000L;public static void main(String[] args) throws InterruptedException {concurrency();serial();}public static void concurrency() throws InterruptedException {long start = System.currentTimeMillis();Thread thread = new Thread(new Runnable() {@Overridepublic void run() {int a = 0;for (int i = 0; i < count; i++) {a += 5;}}});thread.start();int b = 0;for (int i = 0; i < count; i++) {b--;}long time = System.currentTimeMillis() - start;thread.join();System.out.println("concurrency :" + time + "ms,b=" + b);}private static void serial() {long start = System.currentTimeMillis();int a = 0;for (int i = 0; i < count; i++) {a += 5;}int b = 0;for (int i = 0; i < count; i++) {b--;}long time = System.currentTimeMillis() - start;System.out.println("serial: " + time + "ms,b=" + b + ", a=" + a);}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。