public class AccountingSync implements Runnable {
static int i = 0;
public void increase() {
i++;
}
@Override
public void run() {
for (int j = 0; j < 1000000; j++) {
increase();
}
}
public static void main(String[] args) throws InterruptedException {
AccountingSync accountingSync = new AccountingSync();
Thread t1 = new Thread(accountingSync);
Thread t2 = new Thread(accountingSync);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(i);
}
}
public class AccountingSync implements Runnable {
final static Object OBJECT = new Object();
static int i = 0;
public void increase() {
i++;
}
@Override
public void run() {
for (int j = 0; j < 1000000; j++) {
synchronized (OBJECT) {
increase();
}
}
}
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(new AccountingSync());
Thread t2 = new Thread(new AccountingSync());
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(i);
}
}
public class AccountingSync implements Runnable {
static int i = 0;
public synchronized void increase() {
i++;
}
@Override
public void run() {
for (int j = 0; j < 1000000; j++) {
increase();
}
}
public static void main(String[] args) throws InterruptedException {
AccountingSync accountingSync = new AccountingSync();
Thread t1 = new Thread(accountingSync);
Thread t2 = new Thread(accountingSync);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(i);
}
}
public class AccountingSync implements Runnable {
static int i = 0;
public static synchronized void increase() {
i++;
}
@Override
public void run() {
for (int j = 0; j < 1000000; j++) {
increase();
}
}
public static void main(String[] args) throws InterruptedException {
Thread t1 = new Thread(new AccountingSync());
Thread t2 = new Thread(new AccountingSync());
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(i);
}
}
public class BadLockOnInteger implements Runnable {
static Integer i = 0;
@Override
public void run() {
for (int j = 0; j < 1000000; j++) {
synchronized (i) {
i++;
}
}
}
public static void main(String[] args) throws InterruptedException {
BadLockOnInteger badLockOnInteger = new BadLockOnInteger();
Thread t1 = new Thread(badLockOnInteger);
Thread t2 = new Thread(badLockOnInteger);
t1.start();
t2.start();
t1.join();
t2.join();
System.out.println(i);
}
}
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有