public class ThreadTest {
public static void main(String[] args) {
Example example = new Example();
Thread t1 = new Thread1(example);
Thread t2 = new Thread1(example);
t1.start();
t2.start();
}
}
class Example {
public synchronized void excute() {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute:" + i);
}
}
}
class Thread1 extends Thread {
private Example example;
public Thread1(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute();
}
}
public class ThreadTest {
public static void main(String[] args) {
Example example = new Example();
Thread t1 = new Thread1(example);
Thread t2 = new Thread2(example);
t1.start();
t2.start();
}
}
class Example {
public synchronized void excute() {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute:" + i);
}
}
public synchronized void excute1() {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute1:" + i);
}
}
}
class Thread1 extends Thread {
private Example example;
public Thread1(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute();
}
}
class Thread2 extends Thread {
private Example example;
public Thread2(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute1();
}
}
public class ThreadTest {
public static void main(String[] args) {
Example example = new Example();
Example example2 = new Example();
Thread t1 = new Thread1(example);
Thread t2 = new Thread2(example2);
t1.start();
t2.start();
}
}
class Example {
public synchronized static void excute() {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute:" + i);
}
}
public synchronized static void excute1() {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute1:" + i);
}
}
}
class Thread1 extends Thread {
private Example example;
public Thread1(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute();
}
}
class Thread2 extends Thread {
private Example example;
public Thread2(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute1();
}
}
public class ThreadTest {
public static void main(String[] args) {
Example example = new Example();
Thread t1 = new Thread1(example);
Thread t2 = new Thread2(example);
t1.start();
t2.start();
}
}
class Example {
public void excute() {
synchronized (this) {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute:" + i);
}
}
}
public void excute1() {
synchronized (this) {
for (int i = 0; i < 5; ++i) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("excute1:" + i);
}
}
}
}
class Thread1 extends Thread {
private Example example;
public Thread1(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute();
}
}
class Thread2 extends Thread {
private Example example;
public Thread2(Example example) {
this.example = example;
}
@Override
public void run() {
example.excute1();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有